chrisfcarroll / MailMerge

Merge component for OfficeOpenXml .docx (i.e. Microsoft Word) documents
GNU General Public License v3.0
20 stars 7 forks source link

Merging "empty" values #6

Closed dr-consit closed 1 year ago

dr-consit commented 4 years ago

When merging an "empty" value, this library leaves a kind of "placeholder" like this: «MergeField» whereas Microsoft Word just leaves an empty space.

Would it be possible to change this behaviour to match that of Microsoft Word?

I've been able to change the behaviour in my use-case, but apparently all my merge-fields are "complex" merge-fields, and I am unaware of any option to change this in Microsoft Word, so I cannot make a pull request that also covers "regular" merge-fields.

P.S. Just in case it has any value, the change that "fixes" this for me can be seen here: https://github.com/AllTaken/MailMerge/commit/67459f6905d4c94e09404dbe69ee35afa00f0997

Note that in this commit there is also some functionality for "null" values/missing merge-values, to leave the mergefield "as is" and thus available for subsequent merges, I don't know if this is correct, it just felt "more right".

chrisfcarroll commented 4 years ago

It would be possible yes! Probably later this week. I'll check the standard docs about your last para, whether it matches what feels right to you. I think standard behaviour is that for missing values the mergefield is left as-is, but for nulls we should check.

AllTaken commented 3 years ago

Should be fixed for complex mergefields by pr #9

I left out the null stuff.

For a more complete picture I tested what Microsoft Word does, as this is the "canonical behavior" in my use-case.

When a mergefield is missing in the mergefile Microsoft Word presents the user with a dialog allowing the user to either: Remove the missing field (a.k.a. replace with empty) or use the value from another user specified mergefield. The option to remove the missing field is pre-selected.

So for my current use-case, the best option is actually to replace the mergefield with empty string...

chrisfcarroll commented 3 years ago

So let me make sure I understand -- by missing merge field you mean, the docx file has a field named X, but the data source you merge with has no column X? And in this case, Word will throw up a UI, when you start the mailmerge, to ask you?

AllTaken commented 3 years ago

Yes.

Here's an example, when merging a word file, with a merge field named "NonExisting", which is not present in the data source: image

And apparently I was mistaken - there's a separate button to "Remove Field", and the pre-selected option is to replace with the value in the "first" field that is actually present in the data source...

AllTaken commented 3 years ago

Any chance of getting the PR reviewed and/or merged in the near future?

StingyJack commented 1 year ago

When a mergefield is missing in the mergefile Microsoft Word presents the user with a dialog allowing the user to either: Remove the missing field (a.k.a. replace with empty) or use the value from another user specified mergefield. The option to remove the missing field is pre-selected.

So for my current use-case, the best option is actually to replace the mergefield with empty string...

@AllTaken - I would need to disagree with this being the best option. One of the use cases for this is to allow end users to be able to re-run a merge manually if all of the data was not available at the time it was programmatically merged. So if the field value in the dictionary is null, and the merge field is removed, the users cant supply the data and re-merge it.

dr-consit commented 1 year ago

@StingyJack

Yeah a parameter or similar to choose between one or the other, would be best. Anyway, it doesn't seem like @chrisfcarroll has attention on this library.

So probably just fork, do what you wish, and maintain your own fork.

chrisfcarroll commented 1 year ago

Yeah, sorry, I think dr-consit's is right, if you need it soon, fork and diy is the best option. I will try to pay attention to this this year still but I realise that's not a great SLA. If I can pay attention sooner, I'll signal here.

chrisfcarroll commented 1 year ago

Better late than never? I've merged and pushed https://www.nuget.org/packages/MailMerge/2.5.0 . I think what I needed was just to be convinced that merging an empty field was the 'correct' behaviour.

chrisfcarroll commented 1 year ago

I've changed target frameworks to net6.0 netcoreapp3.1 netstandard2.1 because netcore2 isn't supported or on my machine anymore. Hopefully that still covers all the right bases

jimbox13 commented 1 year ago

thank you!

chrisfcarroll commented 1 year ago

Apologies to @dr-consit & @AllTaken for delay in getting back to this and thankyou for taking the trouble to work on it.

chrisfcarroll commented 1 year ago

In https://www.nuget.org/packages/MailMerge/2.5.0