Conditional output

Hi,

I am using TableStart/TableEnd in order to generate “loop” content, sometimes the data source returns the “empty” result and it is legitimate. In this case I would like the whole section between TableStart/TableEnd not to be shown including the merge fields themselves, what would be a way to achieve that?

Thanks.

Michael

Hi Michael,

Thanks for your request. If you use table to show your loop content, then I think you can insert bookmark into this table (as a marker), then check whether data source contains records, and if there are no records in the data source, get the table using bookmark and remove it, otherwise just execute mail merge. In addition, you can just out your region into the separate Word document Section and remove entire section.

Hope this helps. Please let me know if you need more assistance, I will be glad to help you.

Best regards.

Thanks Alexey,

Can you please point me or give a short snippet on how to make this “separate word section” trick.

Thanks.

Michael

Hi Michael,

Thanks for your inquiry. Please follow the link to learn how to work with Section:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/work-with-sections.html

Also see the attached document and the following code. The document contains 3 sections, there is a bookmark in each section. Using this code, we remove the second section from the document, using bookmark as a marker.

// Open the document

Document doc = new Document(“C:\Temp\in.doc”);

// Remove the second section for the docuemnt using a bookmark as a marker.

Bookmark bk = doc.getRange().getBookmarks().get(“sect2”);

if (bk != null)

{

// Get section where the bookmark is located and remove it.

Section sect = (Section)bk.getBookmarkStart().getAncestor(NodeType.SECTION);

if (sect != null)

sect.remove();

}

// Save output document

doc.save(“C:\Temp\out.doc”);

Hope this helps.

Best regards,