Free Support Forum -

Suppressing blank lines if mergefield empty

I have the following problem.

After I execute a merge by calling Document.Mailmerge.Execute(myDataRow), if some of mergefields in the template did not contain data, the blank lines will remain. The standard merge process in MS Word suppresses the empty lines by default. How can I suppress them with Aspose?

I realize that I can manipulate the document programmatically, but I woils like to avoid doing this and simply have the fields suppressed as a result of my merge action. Seems like I am not seeing something simple hereā€¦

What is the best (simplest) way to do it?

I'm just a regular user of Aspose.Words like you (not a support guy).

I had this issue too, so I used the following code to delete empty paragraphs:

Dim Paras As Words.NodeList
Dim ToBeDeleted As New Generic.List(Of Words.Paragraph)
Paras = WDocument.SelectNodes("//Paragraph")
For Each Par As Words.Paragraph In Paras
If Par.ChildNodes.Count = 0 And Par.ParentNode IsNot Nothing Then
End If
For Each EmptyP As Words.Paragraph In ToBeDeleted
Catch ex As Exception
' WriteLog(ex.Message, EventLogEnum.EVENTLOG_ERROR_TYPE, False)
End Try

I hope it helps...



<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your interest in Aspose.Words. I think that you should use MailMerge.RemoveEmptyParagraphs. This property specifies whether paragraphs that contained mail merge fields with no data should be removed from the document. For example see the following code.

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

string[] names = { "FirstName", "LastName", "Address" };

string[] values = { "Alexey", "Noskov", "" };

doc.MailMerge.RemoveEmptyParagraphs = true;

doc.MailMerge.Execute(names, values);


I hope this could help you.

Best regards.

Thanks for the responses.

Alexey, your example is exactly what I was looking for.

Thank you.