Free Support Forum - aspose.com

CleanupOptions Not Working for DataTable Without Rows

Hello,


We have a document that displays several “child” tables. When one of those child tables does not return any rows, then the Merge Fields show on the document which looks pretty ugly. We’ve tried to “clean-up” those merge fields, without success. Here are some supporting resources:

  1. The first attachment shows the document after the merge with the Merge Fields that we need removed. As a reminder, this only happens when the v_SignLic does not contain any rows.
  2. The second attachment shows the code we are using to do the clean-up, which is straight from this blog post: http://www.aspose.com/blogs/blogs/?p=6934

As a related question, do I need to “redeclare” the clean-up options before each .MailMerge.Execute call? Stated another way, right now, I set the clean-up options before each of my executes on this document. It seems a little unnecessary. I’m wondering if setting them once before my first execute will do the trick for all remaining executes.

Thanks for the help!

Jim
Hi James,

Thanks for your inquiry. Please use the MailMerge.CleanupOptions property as show below. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");

doc.MailMerge.ExecuteWithRegions(DataSource ...);

doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveEmptyParagraphs;

doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedRegions;

doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedFields;

doc.MailMerge.CleanupOptions |= Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveContainingFields;

Just a quick note the documentation has the MailMergeCleanupOptions in the aspose.words package not the reporting package

Hi Mark,


Thanks for reporting this. Can you please clarify which page you saw this error on? I will look into fixing it as soon as possible.

Thanks,

Hi,


This project got tabled for a little bit, and now we are back to it. I’ve used your code exactly as shown above, and I still have the same problem. Whenever the data table does not return any rows, my “unused” merge fields still clutter up the document. All I need to do is have those unused fields removed somehow. That seems like it would be basic functionality, when the datatable associated with the mergefields does not contain data.

Any other ideas?

Jim
Hi James,

Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.

Jim,

I encountered the exact same situation that you have described. After much experimenting, I discovered that the "doc.MailMerge.DeleteFields()" function successfully removed all unused fields. This function is executed just before I save the document, since it removes all merge fields.

Tahir,

Please try and find an answer to this, since the "doc.MailMerge.DeleteFields()" function is basically a nuclear solution in that it removes everything and does not provide any of the granularity that the clean-up functions offer.

Alex

Hi Alexander,


Thanks for your inquiry. MailMerge.DeleteFields method removes mail merge related fields from the document. This method removes MERGEFIELD and NEXT fields from the document. This method could be useful if your mail merge operation does not always need to populate all fields in the document. Use this method to remove all remaining mail merge fields.

Regarding the issue posted at this post, Perhaps, you’re using an older version of Aspose.Words; as with Aspose.Words v11.9.0, I am unable to reproduce this problem on my side. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v11.9.0 and let us know how it goes on your side. I hope, this will help.

If you still face problem, please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.