Hi,
I was reading the docs about mail merge cleanup at https://docs.aspose.com/words/net/clean-up-before-or-during-mail-merge/, but it seems I cannot get the REMOVE_EMPTY_PARAGRAPHS option to work.
I have attached a ZIP file which contains two DOC files, personale_it.doc
is the template and custom_test.doc
is the result.
Has you see, the template has regions which contain paragraphs, specifically the gray ones; after the merge if the field titolo_sezione
is empty the gray paragraph is still there, while I’d like it to be removed.
The mail merge is performed with the following code, which uses an XML InputStream:
private static void merge(Document document, InputStream xmlStream, boolean withRegions) throws Exception {
// imposto trigger per merge immagini e HTML, e abilito sintassi Mustache
com.aspose.words.MailMerge mm = document.getMailMerge();
mm.setFieldMergingCallback(new ImageMerge());
mm.setTrimWhitespaces(true);
// creo il dataset
DataSet dataSet = new DataSet();
dataSet.readXml(xmlStream);
// eventuale merge delle regioni
if (withRegions) {
mm.setMergeDuplicateRegions(true);
// imposto pulizia campi non usati
mm.setCleanupOptions(
// rimozione regioni non compilate
MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS
// rimozione righe di tabella vuote
| MailMergeCleanupOptions.REMOVE_EMPTY_TABLE_ROWS
);
// eseguo merge
mm.executeWithRegions(dataSet);
}
// imposto pulizia campi non usati
mm.setCleanupOptions(
// rimozione campi non compilati
MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS
// rimozione campi innestati
| MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS
// rimozione paragrafi vuoti
| MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS
);
// eseguo merge
mm.execute(dataSet.getTables().get(0));
}
What exactly am I doing wrong?
Thanks.
mail_merge_cleanup.zip (70.6 KB)