How to remove empty table / lines in Microsoft Word Mail Merge Template using Aspose.Words REST API

I can get word tables with ‘foreach’ loops working fine if there’s data in a collection, but if it’s an empty set it shows the template fields instead of hiding the table:


Attached is an example of what executeTemplate is producing, and the empty set I’m providing (called “Materials”)

I’ve tried various cleanup options (eg. “?cleanup=UnusedRegions,UnusedFields,ContainingFields”) and it doesn’t seem to do a thing.'

Please help - I’m starting to think executeTemplate is simply not up to production usage yet.

Thanks,

Brendan


Hi Brendan,

To hide merge fields, you can pass empty values to merge fields as you can see in the attached XML. To remove a table in case of empty values, you can use '?cleanup=RemoveTitleRow' parameter.

The limitation of RemoveTitleRow is that it deletes the table if there is only one row in the table and there is no text other than merge fields in the table as you can see in the attached document. You can check this document with the attached XML to see how it deletes the table.

In your case, you have two rows and second row shows the total planned labor / material. RemoveTitleRow will not work in such cases. A new issue to remove complete table if empty values are passed (no matter how many rows are there and if some extra text is present) has been logged into our issue tracking system as SAASWORDS-115. We will keep you updated on this issue in this thread.

Please feel free to contact us in case you have further comments or questions.

Best Regards,

@brendan.knowles

We have already fixed the reported issue. Please use cleanup parameter as following it will resolve the issue. Please let us know if you have any issue or concern.

cleanup=ContainingFields,EmptyParagraphs,UnusedFields,UnusedRegions,RemoveTitleRow,RemoveTitleRowInInnerTables

@brendan.knowles

We have another update, since API Version V4.0 we have simplified the Mail Merge APIs. We have joined the “ExecuteMailMerge” and “ExecuteTemplate” methods. Now API has only “mailmerge” method which can be used with both template types: “mailmerge fields” or “mustashe”. Please feel free to contact us for any further details.