Hi Jens,
Thanks for your inquiry.
ns1045:
Until now we are using setRemoveEmptyRegions() and setRemoveEmptyParagraqphs() to avoid unregnonized fields & regions. I think in aspose version <11.0 these flag were used in the saveprocess of the document.
In 11.10 these two methods and the new one setCleanupOptions() are used in executeMailMerge() process.
Yes, the setRemoveEmptyParagraphs and setRemoveEmptyRegions methods are obsolete. The latest version of Aspose.Words for Java use setCleanupOptions method to gets or sets a set of flags that specify what items should be removed during mail merge. I suggest you please read following documentation link for your kind reference.
https://docs.aspose.com/words/java/aspose-words-for-java/
ns1045:
Our mechanism to execute multiple regions is until now that we have multiple IMailMergeDataSources. We call for each one executeWithRegions(), so the new behaviour removes all regions which dont match the first datasource we use in executeWithRegions. So in next call auf executeWithRegions() with the next datasource all regions are already removed. So our question is: do/did you want that change of behaviour ?
It depends how to use the flags for cleanup procedure. In your case, please do not use MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS for each executeWithRegions call. Please set this Cleanup Option for last call of executeWithRegions as you have mentioned in your post.
https://reference.aspose.com/words/java/com.aspose.words/IMailMergeDataSource
// Create some data that we will use in the mail merge.
CustomerList customers = new CustomerList();
customers.add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
customers.add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));
// Open the template document.
Document doc = new Document(MyDir + "MailingLabelsDemo.doc");
// To be able to mail merge from your own data source, it must be wrapped
// into an object that implements the IMailMergeDataSource interface.
CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS | MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS);
// Now you can pass your data source into Aspose.Words.
doc.getMailMerge().executeWithRegions(customersDataSource);
// This example creates a table, but you would normally load table from a database.
java.sql.ResultSet resultSet = createCachedRowSet(new String[] { "SerialNumber", "Item", "Quantity", "PricePerItem", "Amount" });
addRow(resultSet, new String[] { "1", "Milk", "1", "10", "10"});
com.aspose.words.DataTable Results = new com.aspose.words.DataTable(resultSet, "Result");
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS | MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS);
doc.getMailMerge().executeWithRegions(Results);
com.aspose.words.DataTable Results2 = new com.aspose.words.DataTable(resultSet, "table2");
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS | MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS | MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS);
doc.getMailMerge().executeWithRegions(Results2);
doc.save(MyDir + "MailMerge.CustomDataSource Out.doc");
ns1045:
I have another question concerning CleanupOptions: how to combine multiple cleanup options like removeEmptyParagraphs, removeUnusedRegions, removeUnusedFields… ?
You can combine multiple cleanup options as shown below:
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS | MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS | MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS);