NestedMail Merge

I would like to do somthing like that

My Table in DOC

====================================
II TableStart:Master II
====================================
II Header 1 II Header 2 II
====================================
II TableStart:Detail II<TableEnd:Detial II
II IITableEnd:Master II
====================================

My problem is, on putting the Mergefield for the Master Table in this way, I got the error “TableStart and TableEnd have to be in the same, row, cell or section”.

On making something like that

TableStart:Master
====================================
II II
====================================
II Header 1 II Header 2 II
====================================
II TableStart:Detail II<TableEnd:Detial II
====================================
TableEnd:Master

The problem is, I have for any master always 2 empty rows, but I thats for me a big problem, the tables has to be concatinated!

The MasterDetail I’m doing with DataTable and 2 DataSets …

Can you help me?

thx
Michael

Hi Michael,

Thanks for your inquiry. It would be great if you please share following details for investigation purposes.

  • Please supply us with the input document that is causing the issue
  • Please supply us with the output document showing the undesired behavior
  • Please supply us with the expected document showing the desired behavior (You can create this document using Microsoft Word).

As soon as you get these pieces of information to us we’ll start our investigation into your issue.

Hi Aspose Team,

sorry for my late answer, but I was very busy at work the last week.
But my problem for me is very urgent!

The thing I need, is NO EMPTY ROWS between the MASTER ROWS and also bevor and after the table

in attachment an Tamplate, Result and Expected document

thx for your helb
Michael

Hi Michael,

Thanks for sharing the details. The Result.doc shows the correct mail merge behavior. Please read the rules when marking a region from here:
https://docs.aspose.com/words/java/types-of-mail-merge-operations/

In your case, I suggest you please join the tables after doing mail merge as shown in following code snippet. Hope this helps you. Please let us know if you have any more queries.

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

. . . . Mail Merge Code . . .
. . . . Mail Merge Code . . .
. . . . Mail Merge Code . . .

Node[] tables = doc.getChildNodes(NodeType.TABLE, true).toArray();
if (tables.length> 1)
{
    Table firstTable = (Table) tables[0];
    for (int i = 1; i <tables.length; i++)
    {
        // Due to the design of tables even tables with different cell count and widths can be joined into one table.
        while (((Table) tables[i]).hasChildNodes())
            firstTable.getRows().add(((Table) tables[i]).getFirstRow());
        ((Table) tables[i]).remove();
    }
}
doc.save(MyDir + "out.docx");

Ok, but I have a lot of tables in my doc. I have to merge only that one in my Master Region.
How can I for example get the Table ChildNodes from a Bookmark?
Or what do you think I have to do?

For now I always loop my result set and construct my master detail table by copying rows and column by the way, but that is very very slow! One print with a lot of operations and records need 5 minutes so I would try to resolving this problem with your DataSet in the hope it is faster than my way.

In 50% of my prints I need a MasterDetail on Tables like my example!

So what’s your idea for me?

thx
Michael

Hi Michael,

Thanks for your inquiry. In this case, you can get the tables generated during mail merge operation by implementing IFieldMergingCallback interface as shown in following MergeTable class. By using this approach, you will get the list of tables in ArrayList. You can join these table before saving the table. Please use the following code snippet to achieve your requirements and let us know if you have any more queries.

public class MergeTable implements IFieldMergingCallback
{
    private DocumentBuilder mBuilder;
    public ArrayList tables = new ArrayList();
    public void fieldMerging(FieldMergingArgs e) throws Exception
    {
        if (mBuilder == null)
        {
            mBuilder = new DocumentBuilder(e.getDocument());
        }
        // First field of Master Table, use any field of your master table
        if (e.getFieldName().equals("ENTI_INDIC_I"))
        {
            tables.add(e.getField().getStart().getAncestor(NodeType.TABLE));
        }
    }
    public void imageFieldMerging(ImageFieldMergingArgs args) throws Exception
    {}
}
com.aspose.words.DataSet ds = new com.aspose.words.DataSet();
ds.getTables().add(datatable);
ds.getTables().add(datatable2);
Document doc = new Document(MyDir + "Template.doc");
MergeTable mTables = new MergeTable();
doc.getMailMerge().setFieldMergingCallback(mTables);
doc.getMailMerge().executeWithRegions(ds);
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");

Ok, now there are two problems:

First:
After the merging the “master tables” all the EMPTY LINES between them are now at the end of the new big master table, see “Result.jpg”.
It’s not a big problem have the empty line frome my MergeFields «TableStart:SCHE_N_1_MASTER» and «TableEnd:SCHE_N_1_MASTER» but it’s a problem to have all the other new empty lines.

Second:
I’m not able to generate a MasterDetail, The “master tables” are ok (Test Schule 2, Test Schule 2a, Test Schule 2b, Test Schule 2c) but the mergefields in the “detail tables” for 2a, 2b and 2c, are always empty and not merged!

But my result set is ok

thx
Michael

Hi Michael,

Thanks for your inquiry.

*michael.burger@siag.it:
After the merging the “master tables” all the EMPTY LINES between them are now at the end of the new big master table, see “Result.jpg”.

It’s not a big problem have the empty line frome my MergeFields «TableStart:SCHE_N_1_MASTER» and «TableEnd:SCHE_N_1_MASTER» but it’s a problem to have all the other new empty lines.
To remove empty lines (Empty Paragraph) , please use MailMerge.setCleanupOptions with MailMergeCleanupOptions. Please read following documentation links for your kind refernece.
https://docs.aspose.com/words/java/clean-up-before-or-during-mail-merge/

doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS |MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);

*michael.burger@siag.it:
I’m not able to generate a MasterDetail, The “master tables” are ok (Test Schule 2, Test Schule 2a, Test Schule 2b, Test Schule 2c) but the mergefields in the “detail tables” for 2a, 2b and 2c, are always empty and not merged!

Please make sure that you have correct relationship between Master and Master Detail tables.
https://docs.aspose.com/words/java/nested-mail-merge-with-regions/
Please check the following code snippet for your kind reference.

java.sql.ResultSet resultSet = createCachedRowSet(new String[] { "ENTI_INDIC_I", "ID" });
addRow(resultSet, new String[] { "Record 1", "1" });
addRow(resultSet, new String[] { "Record 2", "2" });
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[] { " Detail 1", "Detail 1 ", "1" });
addRow(resultSet2, new String[] { " Detail 2", "Detail 2 ", "1" });
addRow(resultSet2, new String[] { " Detail 3", "Detail 3 ", "2" });
addRow(resultSet2, new String[] { " Detail 4", "Detail 4 ", "2" });
addRow(resultSet2, new String[] { " Detail 5", "Detail 5 ", "2" });
addRow(resultSet2, new String[] { " Detail 6", "Detail 6 ", "2" });

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 + "Java-out.docx");

Thx for your answer!

Ok for the empty PARAGRAPHS, if I do

doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS |MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);

I don’t have to do the thing with the setFieldMergingCallback !!
I used the setCleanupOptions also in other projects, but I forgot it! so SORRY

For my second problem I’m doing this

DataSet schedaNumero1DataSet = new DataSet();

DataTable schedaNumero1DataTableMaster = new DataTable(DBConnection.getResultSet(connection, "SELECT DISTINCT (ENTI_ID) as ID, ENTI_INDIC_I, ENTI_INDIC_D FROM (" + sqlSchedaNumero1 + ")"), "SCHE_N_1_MASTER");
schedaNumero1DataSet.getTables().add(schedaNumero1DataTableMaster);

DataTable schedaNumero1DataTableDetail = new DataTable(DBConnection.getResultSet(connection, "SELECT ENTI_ID as ID, SCHE_INDIC_I, PROD_DENOMINAZIONE FROM (" + sqlSchedaNumero1 + ")"), "SCHE_N_1_DETAIL");
schedaNumero1DataSet.getTables().add(schedaNumero1DataTableDetail);

schedaNumero1DataSet.getRelations().add(new DataRelation("DataRelation", schedaNumero1DataTableMaster.getTableName(), schedaNumero1DataTableDetail.getTableName(), new String[] { "ID" }, new String[] { "ID" }));

docTemp.getMailMerge().executeWithRegions(schedaNumero1DataSet);

i will send you also the result of my ResultSet (only a set of results)
as you can see I think I’m doing the right thing …I think there is a problem with the COLUMN NAMES returned form the querys … a bug?

Code:

ResultSet master = DBConnection.getResultSet(connection, "SELECT DISTINCT (ENTI_ID) as ID, ENTI_INDIC_I, ENTI_INDIC_D FROM (" + sqlSchedaNumero1 + ")");
System.out.println("MASTER");
while (master.next()) {
	System.out.println("ID : " + master.getObject("ID") + "; ENTI_INDIC_I : " +master.getObject("ENTI_INDIC_I"));
}
			
ResultSet detail = DBConnection.getResultSet(connection, "SELECT ENTI_ID as ID, SCHE_INDIC_I, PROD_DENOMINAZIONE FROM (" + sqlSchedaNumero1 + ")");			
System.out.println("Detail");
while (detail.next()) {
	System.out.println("ID : " + detail.getObject("ID") + "; SCHE_INDIC_I : " +detail.getObject("SCHE_INDIC_I") + "; PROD_DENOMINAZIONE : " +detail.getObject("PROD_DENOMINAZIONE"));
}

Output

MASTER
ID : 7409; ENTI_INDIC_I : Test Schule 2
ID : 7429; ENTI_INDIC_I : Test Schule 2a
ID : 7430; ENTI_INDIC_I : Test Schule 2b
ID : 7431; ENTI_INDIC_I : Test Schule 2c
Detail
ID : 7409; SCHE_INDIC_I : Acetone; PROD_DENOMINAZIONE : Carlo Erba Reagenti Spa
ID : 7409; SCHE_INDIC_I : Acetato di acido acetico etilico; PROD_DENOMINAZaIONE : Hedinger GmbH
ID : 7429; SCHE_INDIC_I : Toner; PROD_DENOMINAZIONE : Verschiedene Lieferanten/Produttori vari
ID : 7429; SCHE_INDIC_I : Toner nero per Vi-310L; PROD_DENOMINAZIONE : Kyocera Mita Corporation
ID : 7430; SCHE_INDIC_I : Acetone; PROD_DENOMINAZIONE : Carlo Erba Reagenti Spa
ID : 7430; SCHE_INDIC_I : Acetato di acido acetico etilico; PROD_DENOMINAZIONE : Hedinger GmbH
ID : 7431; SCHE_INDIC_I : Acetone; PROD_DENOMINAZIONE : Carlo Erba Reagenti Spa
ID : 7431; SCHE_INDIC_I : Acetato di acido acetico etilico; PROD_DENOMINAZIONE : Hedinger GmbH
ID : 7431; SCHE_INDIC_I : Acetilacetone per analisi; PROD_DENOMINAZIONE : Riedel-de Haen AG

so what’s the problem?

thx Michael

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");

Also on the last ASPOSE WORDS version it doesn’t works!

My docs for the template and filest result are attachted.

I tried also your test case and IT WORKS. But I was sure your case works fine, but in my opinion there is a big difference between your “createCachedRowSet” and the ResultSet getting from DB.

I’m not duing any stranged in my code :

docTemp.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);

DataSet schedaNumero1DataSet = new DataSet();
DataTable schedaNumero1DataTableMaster = new DataTable(DBConnection.getResultSet(connection, "SELECT DISTINCT (ENTI_ID) as ID, ENTI_INDIC_I, ENTI_INDIC_D FROM (" + sqlSchedaNumero1 + ")"), "SCHE_N_1_MASTER");
schedaNumero1DataSet.getTables().add(schedaNumero1DataTableMaster);
DataTable schedaNumero1DataTableDetail = new DataTable(DBConnection.getResultSet(connection, "SELECT ENTI_ID as ID, SCHE_INDIC_I, PROD_DENOMINAZIONE FROM (" + sqlSchedaNumero1 + ")"), "SCHE_N_1_DETAIL");
schedaNumero1DataSet.getTables().add(schedaNumero1DataTableDetail);
schedaNumero1DataSet.getRelations().add(new DataRelation("DataRelation", schedaNumero1DataTableMaster.getTableName(), schedaNumero1DataTableDetail.getTableName(), new String[] { "ID" }, new String[] { "id" }));

docTemp.getMailMerge().executeWithRegions(schedaNumero1DataSet);

Try to create a Oracle DB with this case and use a ResultSet getting from DB and not getting from your createCachedRowSet.

As you can see in my ResultFailed.doc the MASTER Tables (Test Schuld 2, Test Schule 2a, Test Schule 2b, Test Schule 2c) are ok.
BUT as you can see the first DETAIL for “Test Schul 2” with two rows are there and that’s OK!
Aspose understands that the first two rows with the ID 7409 are for the first MASTER and the third row with die ID 7429 are a new MASTER, so ASPOSE stops the FIRST DETAIL, BUT doesn’t start the second DETAIL as you can see in my DOC.

I think there is a BIG difference from my RESULTSET and your createdCachedRowSet!

You do anythings with VARCHAR (Strings) but perhapse there is a problem with handling types!!

Hi Michael,

Thanks for your inquiry. Perhaps you are using ResultSet.TYPE_FORWARD_ONLY in Connection.createStatement method, please use ResultSet.TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE as shown in following code snippet. Hope this helps you.

Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
s.execute("SELECT * FROM SCHE_N_1_MASTER");
ResultSet resultSet = s.getResultSet();

Hi Michael,

Further to my last post, the incorrect results you are getting for your scenario is due to ResultSet type TYPE_FORWARD_ONLY . I have logged this issue as WORDSJAVA-707 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

YEAH

that’s working for me, also on the older AsposeWords

stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

The estranged thing is, ResultSet of Oracle should not bee navigable … so what is different from not setting this option?

With setting

docTemp.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);

I don’t have to use your code for delete tables, I’m right? Or is there still a reason for use it?

Thx
Michael

Hi Michael,

Thanks for your inquiry.

michael.burger@siag.it:
The estranged thing is, ResultSet of Oracle should not bee navigable … so what is different from not setting this option?

The com.aspose.words.DataTable creates an object by wrapping the specified ResultSet. In your previous posts you mentioned that you are facing issue while generating MasterDetail contents. This is a bug. I logged this issue as WORDSJAVA-707 in our issue tracking system. We will update you via this forum thread once this issue is resolved.

michael.burger@siag.it:
I don’t have to use your code for delete tables, I’m right? Or is there still a reason for use it?

Please not that Aspose.Words tries to mimic the same behavior as MS Word do. There are empty Paragraphs after each table. Please see the attached image. When these empty Paragraphs are deleted manually by using MS Word, MS Word automatically merges these two consecutive Tables into one.

Aspose.Words do the same when you use MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS option.

Hope this answers your query. Please let us know if you have any more queries.

OMG an other problem

first of all I set the the cleanupOptions,

and then I have two DataSets with to executeWithRegions!
The problem is on the first executeWithRegions it deletes also the empty second Table for the second executeWithRegion.

Aaaahhh

code:

logger.debug("============== SET CLEANUP OPTIONS ==============")

docTemp.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);

logger.debug("============== SCHEDA NUMERO 1 ==================");
String sqlSchedaNumero1 = stmt.getString(4);
logger.debug("Query : " + sqlSchedaNumero1);
DataSet schedaNumero1DataSet = new DataSet();
DataTable schedaNumero1DataTableMaster = new DataTable(DBConnection.getResultSet(connection, "SELECT DISTINCT (ENTI_ID), ENTI_INDIC_I, ENTI_INDIC_D FROM (" + sqlSchedaNumero1 + ")"), "SCHE_N_1_MASTER");
schedaNumero1DataSet.getTables().add(schedaNumero1DataTableMaster);
DataTable schedaNumero1DataTableDetail = new DataTable(DBConnection.getResultSet(connection, sqlSchedaNumero1), "SCHE_N_1_DETAIL");
schedaNumero1DataSet.getTables().add(schedaNumero1DataTableDetail);
schedaNumero1DataSet.getRelations().add(new DataRelation("DataRelationScheN1", schedaNumero1DataTableMaster.getTableName(), schedaNumero1DataTableDetail.getTableName(), new String[] { "ENTI_ID" }, new String[] { "ENTI_ID" }));
logger.debug("start executeWithRegions");
docTemp.getMailMerge().executeWithRegions(schedaNumero1DataSet);
logger.debug("end executeWithRegions");

logger.debug("============== SCHEDA NUMERO 2 ==================");
String sqlSchedaNumero2 = stmt.getString(5);
logger.debug("Query : " + sqlSchedaNumero2);
DataSet schedaNumero2DataSet = new DataSet();
DataTable schedaNumero2DataTableMaster = new DataTable(DBConnection.getResultSet(connection, "SELECT DISTINCT (ENTI_ID), ENTI_INDIC_I, ENTI_INDIC_D FROM (" + sqlSchedaNumero2 + ")"), "SCHE_N_2_MASTER");
schedaNumero2DataSet.getTables().add(schedaNumero2DataTableMaster);
DataTable schedaNumero2DataTableDetail = new DataTable(DBConnection.getResultSet(connection, sqlSchedaNumero2), "SCHE_N_2_DETAIL");
schedaNumero2DataSet.getTables().add(schedaNumero2DataTableDetail);
schedaNumero2DataSet.getRelations().add(new DataRelation("DataRelationScheN2", schedaNumero2DataTableMaster.getTableName(), schedaNumero2DataTableDetail.getTableName(), new String[] { "ENTI_ID" }, new String[] { "ENTI_ID" }));
logger.debug("start executeWithRegions");
docTemp.getMailMerge().executeWithRegions(schedaNumero2DataSet);
logger.debug("end executeWithRegions");

Hi Michael,

Thanks for your inquiry. The behavior of Aspose.Words is correct in your case. I suggest you please call MailMerge.setCleanupOptions just before last call of MailMerge.executeWithRegions method in your code.

If you use following line of code before all calls of MailMerge.executeWithRegions, the cleanup operation removes empty paragrapahs, unused regions (In your case, the second mail merge regions) and unused fields.

doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);

Please read more about MailMergeCleanupOptions from here:
https://reference.aspose.com/words/java/com.aspose.words/mailmergecleanupoptions

You may also call MailMerge.setCleanupOptions method for each MailMerge.executeWithRegions method with different MailMergeCleanupOptions. In the following code snippet, the first call of setCleanupOptions method only removes the empty paragraph. The second call of setCleanupOptions method removes the empty paragrapahs, unused regions and unused fields. Hope this answers your query. Please let us know if you have any more queries.

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

doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS);
doc.getMailMerge().executeWithRegions(dataSet);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
doc.getMailMerge().executeWithRegions(dataSet1);

It was the first what I had tried, to put the setCleanupOptions to other positions!
But I got this error
unexpected end of children nodes reached
described here
https://forum.aspose.com/t/49052

After some studying the problem and understand the problem is something in the section. I don’t know what was wrong, but I have 6 MasterDetail Tabels and some one works and some one not! So I copied that one which works to the one which doesn’t and edit the regions for any MasterDetail Table
So I think now anything works, also without the version 11.10 as described in the post.

p.s.
for now I will use only
MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS

thx a lot for your help!!!

Michael

Hi Michael,

It is nice to hear from you that now everything is working at your end. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

The issues you have found earlier (filed as WORDSJAVA-707) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)