We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Does Aspose.words for java support hiding table based on condition


I have a requirement where I have to hide/show a table based on a condition. Does aspose.words for java have a way of doing it?

In docx itself, I tried putting an IF condition and inside if condition I placed the table itself which helped.

But, just wondering how to do the same using aspose.words.

Please let me know.

Thanks & Regards,
Sivaraj. I

Hi Sivaraj,

Thanks for your inquiry. Please use the following code example to achieve your requirements. Hope this helps you.

If you still face problem, please share your expected output document here for our reference. We will then provide you more information about your query along with code.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// We want to insert a field like this:

// { IF 1 = 1 table contents "Simple text" }

Field field = builder.insertField("IF ");


builder.write(" 1 = 1 ");

// We call this method to start building the table.



builder.write("Row 1, Cell 1 Content.");

// Build the second cell


builder.write("Row 1, Cell 2 Content.");

// Call the following method to end the row and start a new row.


// Build the first cell of the second row.


builder.write("Row 2, Cell 1 Content");

// Build the second cell.


builder.write("Row 2, Cell 2 Content.");


// Signal that we have finished building the table.


builder.write(" \"Simple text\" ");

// Finally update the outer field to recalcaluate the final value. Doing this will automatically update

// the inner fields at the same time.


doc.save(MyDir + "Out.docx");