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

Free Support Forum - aspose.com

Need urgent help

If I want to hide mergefields in docx using mergefields which can be empty or boolean, how can we achieve that.

Consider multiple fields I need to hide(like table, standalone, etc) based on single boolean flag

Hi there,


Thanks for your inquiry. In your case, I suggest you please insert the contents inside If Field which you want to hide. Please check the attached sample input document and following code example for your kind reference.

Hope this helps you. Please let us know if you have any more queries.


Document doc = new Document(MyDir + "in.docx");

com.aspose.words.DataTable dataTable = new DataTable("MainRegion");

dataTable.getColumns().add("Field1");

DataRow row = dataTable.newRow();

dataTable.getRows().add(row);

row.set(0, "1");

com.aspose.words.DataTable dataTable1 = new DataTable("Test");

dataTable1.getColumns().add("FieldinTable");

DataRow row1 = dataTable1.newRow();

dataTable1.getRows().add(row1);

row1.set(0, "true value");

com.aspose.words.DataTable dataTable2 = new DataTable("Test2");

dataTable2.getColumns().add("FieldinTable");

DataRow row2 = dataTable2.newRow();

dataTable2.getRows().add(row2);

row2.set(0, "false value");

DataSet ds = new DataSet();

ds.getTables().add(dataTable);

ds.getTables().add(dataTable1);

ds.getTables().add(dataTable2);

doc.getMailMerge().executeWithRegions(ds);

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