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

Hi,


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.moveTo(field.getSeparator());

builder.write(" 1 = 1 ");

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

builder.startTable();

builder.insertCell();

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

// Build the second cell

builder.insertCell();

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

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

builder.endRow();

// Build the first cell of the second row.

builder.insertCell();

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

// Build the second cell.

builder.insertCell();

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

builder.endRow();

// Signal that we have finished building the table.

builder.endTable();

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.

field.update();

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