Remove empty nested table

Hello,

I have a .doc template where I am using a table nested within a parent table. Sometimes, the nested table is empty while the parent table has some data, so I would just like to remove the nested table from the output document. I am currently using a subclass from DocumentVisitor found in this thread : Problem merging with empty table - #2 by adam.skelton - Free Support Forum - aspose.com, that I translated into java. It works perfectly when both tables are empty, but when only the nested table is empty, it is not removed, since the “tablestart” field from the nested table is not found when the visitor does its work (even though it is visible in the output document). Does someone have some hints about this problem ?

thanks in advance for the help.

Hi
Thanks for your request. Do you use Mail Merge feature to fill the document with data? If so, you can just set RemoveEmptyRegions option, in this case empty regions will be removed upon mail merge:
https://reference.aspose.com/words/java/com.aspose.words/MailMergeCleanupOptions
If you do not use mail merge, then please attach the document where you need to remove empty tables, I will check it and provide you more information.
Best regards,

My problem (with both methods) came from the fact that when my dataset was empty, I did not perform the mailmerge and then nothing was deleted. Just works perfectly now.

Thanks a lot for the help,
regards.

Hi
It is perfect that you managed to resolve the problem. Please let me know if you need more assistance, I will be glad to help you.
Best regards,

Hi,

Your answer worked for our new version of product where we use new version of Aspose.Words. But when I wanted to merge the fix to older version where we have used older version of Aspose.Words this property does not exists, and the empty region is not removed automatically. In fact the region is not empty. The region is as below.

<TableStart:Parent>
<Total>
<TableStart:Child><Numbers> <TableEnd:Child>
<TableEnd:Parent>

When the MailMerge.ExecuteWithRegions is executed, in case parent has value but child not it still shows Numbers, but if parent does not have any value Total is not shown (As it should not).

Would you please let me know how can I fix this problem in older version where “RemoveEmptyResions” is not introduced.

Thank you i advance,

Hello
Thanks for your request. In this case you can try using RemoveEmptyRegions class:

// Open the template document
Document doc = new Document(@"in.doc");
// Merge data
doc.MailMerge.ExecuteWithRegions(Dataset);
// Remove any remaining unused regions from the document
doc.Accept(new RemoveEmptyRegions());

RemoveEmptyRegions class is attached.
Best regards,