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…
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
ToBeDeleted.Add(Par)
End If
Next
For Each EmptyP As Words.Paragraph In ToBeDeleted
Try
EmptyP.ParentStory.Paragraphs.Remove(EmptyP)
Catch ex As Exception
' WriteLog(ex.Message, EventLogEnum.EVENTLOG_ERROR_TYPE, False)
End Try
Next
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.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.