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

Free Support Forum - aspose.com

RemoveEmptyParagraphs not working

Hi,
Im using Aspose.Words v. 16.11.0.0
I have 6 mergefield of which 3 of them are blanks (empty string)
As far as i can read, if I use the following setting:

doc.MailMerge.CleanupOptions = MailMerging.MailMergeCleanupOptions.RemoveEmptyParagraphs

It is supposed to remove the mergefield + row entirely and thereby not insering a blank row.
But the blank row is still there - how can I remove it?
I have tried to use all the settings in the CleanupOptions, but nothing is working for me.

Im using the following code, and have attached the document I use:

Dim doc As New Aspose.Words.Document("C:\Test\KollektivTest.docx")
Dim fieldnames As New List(Of String)
Dim values As New List(Of String)()

fieldnames.Add("Adresse_Navn")
values.Add("Test")

fieldnames.Add("Adresse_Navn2")
values.Add("")

fieldnames.Add("Adresse_CO")
values.Add("")

fieldnames.Add("Adresse_Adresse")
values.Add("Test2")

fieldnames.Add("Adresse_Lokalby")
values.Add("")

fieldnames.Add("Adresse_Postby")
values.Add("Test3")

doc.MailMerge.CleanupOptions = MailMerging.MailMergeCleanupOptions.RemoveEmptyParagraphs
doc.MailMerge.Execute(fieldnames.ToArray(), values.ToArray())
doc.Save("C:\Test\Lala_" + Guid.NewGuid().ToString() + ".pdf", SaveFormat.Pdf)

Hi Thomas,

Thanks for your inquiry. You are facing the expected behavior of Aspose.Words. Your document contains “–” + Line Break + Mail Merge field in one paragraph. See the attached image for detail.

Please remove “–” from the document to get the desired output. Or put "–" and Line Break in separate paragraph.

Hi again,
Thank you - the attached document was a simplyfication of the original document, but the “paragraph fix” pointed me in the right direction, and now it works with the “RemoveEmptyParagraphs” setting

Hi Thomas,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.