Free Support Forum - aspose.com

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 : http://www.aspose.com/community/forums/263476/problem-merging-with-empty-table/showthread.aspx#263476, 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.

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:SimSun; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

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:

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/mailmerge.html#RemoveEmptyRegions

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,