Hi Michael,
Thanks for your inquiry. Perhaps, you are using an older version of Aspose.Words; as with Aspose.Words v13.2.0, I am unable to reproduce the master detail problem at my side. I have created the same DataSet as of yours. Please see the following code snippet. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v13.2.0 and let us know how it goes on your side. I hope, this will help.
If the problem still remains, please share following details for investigation purposes.
- Please execute the following code snippet at your end and share the output document.
- Please supply us with the output document showing the undesired behavior.
- Please make sure that you are using correct columns names in your template document.
java.sql.ResultSet resultSet = createCachedRowSet(new String[] { "ENTI_INDIC_I", "ID" });
addRow(resultSet, new String[] { "Test Schule 2", "7409" });
addRow(resultSet, new String[] { "Test Schule 2a", "7429" });
addRow(resultSet, new String[] { "Test Schule 2b", "7430" });
addRow(resultSet, new String[] { "Test Schule 2c", "7431" });
com.aspose.words.DataTable datatable = new com.aspose.words.DataTable(resultSet, "SCHE_N_1_MASTER");
java.sql.ResultSet resultSet2 = createCachedRowSet(new String[] { "SCHE_INDIC_I", "PROD_DENOMINAZIONE", "ID" });
addRow(resultSet2, new String[] { " Acetone", " Carlo Erba Reagenti Spa ", "7409" });
addRow(resultSet2, new String[] { " Acetato di acido acetico etilico", " Hedinger ", "7409" });
addRow(resultSet2, new String[] { " Toner", " Verschiedene Lieferanten/Produttori vari", "7429" });
addRow(resultSet2, new String[] { " Toner nero per Vi-310L", " Kyocera Mita ", "7429" });
addRow(resultSet2, new String[] { "Acetone", " Carlo Erba Reagenti Spa ", "7430" });
addRow(resultSet2, new String[] { " Acetato di acido acetico etilico", " Hedinger GmbH ", "7430" });
addRow(resultSet2, new String[] { " Acetone", " Carlo Erba Reagenti Spa", "7431" });
addRow(resultSet2, new String[] { " Acetato di acido acetico etilico", " Hedinger GmbH", "7431" });
addRow(resultSet2, new String[] { " Acetilacetone per analisi", " Riedel-de Haen AG ", "7431" });
com.aspose.words.DataTable datatable2 = new com.aspose.words.DataTable(resultSet2, "SCHE_N_1_DETAIL");
com.aspose.words.DataSet dataSet = new com.aspose.words.DataSet();
dataSet.getTables().add(datatable);
dataSet.getTables().add(datatable2);
dataSet.getRelations().add(new DataRelation("DataRelation", datatable.getTableName(), datatable2.getTableName(), new String[] { "ID" }, new String[] { "ID" }));
Document doc = new Document(MyDir + "Template_1.doc");
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
MergeTable mTables = new MergeTable();
doc.getMailMerge().setFieldMergingCallback(mTables);
doc.getMailMerge().executeWithRegions(dataSet);
if (mTables.tables.size() > 1)
{
Table firstTable = (Table)mTables.tables.get(0);
for (int i = 1; i < mTables.tables.size(); i++)
{
// Due to the design of tables even tables with different cell count and widths can be joined into one table.
while (((Table)mTables.tables.get(i)).hasChildNodes())
firstTable.getRows().add(((Table)mTables.tables.get(i)).getFirstRow());
((Table)mTables.tables.get(i)).remove();
}
}
doc.save(MyDir + "Out.docx");