Query on the Aspose.Words mail merge cleanup option MailMergeCleanupOptions.RemoveContainingFields

Aspose version: Aspose Words.NET version 23.6.0

Hi,

I have a query re the MailMergeCleanupOptions.RemoveContainingFields option when performing a merge. The Aspose documentation states:

"A merge field can be contained within another field such as an IF field or a formula field. Remove this outer field when the merge field is merged or removed from the document.
Note: This option will only remove a containing field if the field was actually merged with data or if the merge field was removed by using the RemoveUnusedFields option. This option matches the behavior of Microsoft Word during mail merge which always automatically removes outer fields from a merged field and keeps only the plain text result."

We use this cleanup option to remove the IF statements from the merged documents and I need to understand a little more about how this option works. Essentially, I need to explain to myself and others why a particular change to our current Aspose implementation is necessary (because of a separate issue concerning IF statements with merge regions - which has kindly been dealt with in this forum).

Supplied Test Case:

  1. The document in.docx contains some basic test IF statements – the 4th containing a merge region as the true result.
  2. The merge source code (source.docx). (The merge callback handler and the output diagnostics [diag.txt] are just there to help – to attempt to monitor how the merge progresses). The source is a static class where Start() is the entry point.
  3. The merge source code reads the template document (in.docx) and merges it in 2 different ways:

Experiment 1:

  1. main merge.
  2. the region merge.
  3. produces out.do-not-remove-containing-fields.docx.

Experiment 2:

  1. main merge + MailMergeCleanupOptions.RemoveContainingFields enabled.
  2. the region merge.
  3. produces out.remove-containing-fields.docx.

Experiment 1 works as ‘expected’. In test 4 the 2 rows are merged in and the Alt-F9 can be used to toggle the IF statement.

Experiment 2 works as ‘expected’; the IF statements are removed and cannot be toggled by Alt-F9. However, test 4 produces no result (different to Experiment 1 above).

It looks as if the act of removing containing fields on the main merge is also removing the merge region in test 4. The diagnostics (diag.txt) seem to suggest this is the case. After the merge which happens on line 16 (in diag.txt) the region merge fields are removed.

May I ask please, would it be possible to pass on a little more information on the behaviour of the RemoveContainingFields option – specifically why it would be removing the region merge fields. As I say, it looks like we need to make a change to our Aspose implementation to cater for this, but I need to explain the reasoning for the change to myself and others.

Kind regards,

James

in.docx (18.6 KB)

source.docx (16.8 KB)

@JamesMurdoch Looks like an incorrect behavior.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26922

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Have you consider using LINQ Reporting Engine instead of Mail Merge? You can use <<if>> condition instead of IF field. And <<foreach>> instead of regions.

Thank you for looking into this Alexey.

I will look into the LINQ Reporting Engine - thank you for the prompt.

Regards

James

1 Like