As of v9.1- Merge fields remain in document after ExecuteWithRegions on an empty datatable

In version 8.2.1 of Aspose.Words, we were able to perform an ExecuteWithRegions on an empty data table, and it would render as expected (no rows, and no merge fields showing). As of 9.1 (including 9.3), the merge tokens are not getting cleared.

I’ve attached an example app & word document. If you add an Aspose 8.2.1 reference, you’ll find that the merge tokens go away, as expected. If you add a 9.1 reference, they remain after a merge with an empty table.

Is this a bug, or are we overlooking something?

Thanks,
Keith Boudreau

Hi Keith,
Thanks for your inquiry.
You are absolutely correct, the behaviour of removing non merged regions appeared in older versions but was removed starting in 9.1. We have had other requests regarding this issue and realise that some customers use this functionality to remove any unused regions from their documents. We will look into supporting this again in a future verison. Your request has been linked and you will be notified of any developments.
In the mean time you can use this class that I wrote for other customers with same request. It is attached to this post, and you invoke it after merging like this:

doc.MailMerge.ExecuteWithRegions(exampleTable);
doc.Accept(new RemoveEmptyRegions());
doc.Save("Test out.doc");

If you have any further queries please feel free to ask.
Thanks,

Adam-

Thank you so much - it works great!

Keith

Adam-

actually, I have to take that back. It works great when merging one table. But when there are multiple tables on the word template, we’re finding that tables which should have data are also cleared. For now, we’re reverting to 8.2.1. Please let us know if you have any updates or advice.

Keith

Hi Keith,
Could you please post your documents here for testing? I will take a closer look for you.
Thanks,

The issues you have found earlier (filed as 17666) have been fixed in this update.

Hi,
We are running Aspose.Words for .NET version 10.3.0.0, specifically the net1.1 DLL. It would appear as though this fix did not make it into this DLL as an empty table still leaves the definition row in the Word table.
Thanks,
Will SKou

Hi Will,
Thanks for your request. Please make sure you have set removeEmptyRegions option as described here:
https://reference.aspose.com/words/net/aspose.words.mailmerging/mailmergecleanupoptions/
Best regards,