how to use Aspose to conditionally show a table and hide another table in word template?

I have a word template with two table, I want to use Aspose to show a table and hide another table in word template based on a variable in java code, how to achieve this?


You can easily achieve what you need using IF field in your MS Word template document. in the condition you can insert a merge field or a bookmark and then update the condition upon execution mail merge or setting bookmark value using Aspose.Words. For example, see the screenshot of the template document and the code to execute mail merge using Aspose.Words. enter image description here

Document doc = new Document("C:\Temp\in.docx");
doc.getMailMerge().execute(new String[] { "test" }, new String[] { "first" });"C:\Temp\out.docx");

If the output format is supposed to be MS Word document, you can also call Document.unlinkFields() method before saving, in this case IF field will be removed from the document and only the result will be preserved.