Suppress Blank Lines in Word Document - Aspose.Words for .NET

In the word document template if the merge fields are blank then i have a blank line in the document.
Ex: Given below are few merge fields i am using.
«ContactAddress» ----- Test
«ContactAddress2» ------ Blank Value
«ContactCity», «ContactState» «ContactZipCode» ----- ABC, TX 11111
Since we have ContactAddress2 blank i need to see the info in Word document as
Test
ABC, TX 11111
and not as
Test
ABC, TX, 11111
How can i suppress the blank lines?
Thanks
V

This message was posted using Aspose.Live 2 Forum

Hi

Thanks for your inquiry. I think, in your case, you can try using MailMerge.RemoveEmptyParagraphs option to remove empty paragraphs during mail merge process. See the following link for more information:
https://reference.aspose.com/words/net/aspose.words.mailmerging/mailmerge/cleanupoptions/
Please let me know if you need more assistance, I will be glad to help you.
Best regards,

Hi Andrey
This is not working. I still have the blank line. Let me know how i can fix this.
Thanks
V

Hi

Thanks for your request. Could you please attach your input document here for testing? I will check the problem on my side and provide you more information.
Best regards,

Attached are the input and output.

Hi

Thank you for additional information. MailMerge.RemoveEmptyParagrapgs works when the paragraph which contains MergField is empty. In your template you use tab inside paragraph. Please try refactoring your document to avoid using tab. If you need to move MergFields right, please try using paragraph indent instead of tab.
Best regards,

Please see the sample word document template. Please take a look at EnvCoverages and AutoCoverages merge fields. Mergefields are formatted to have multiple tabs with alignment. The way we are now providing the value to these field value is creating a string value with tabs and carriage returns. Thats the reason we were using the tabs on the mergefields so the values appear in that format. Our letters are highly formatted. How i can use paragraph indents to do what tabs can achieve?
Thanks
V

Hi
Thank you for additional information. I cannot reproduce the problem:

Document doc = new Document("Example4.docx");
doc.MailMerge.RemoveEmptyParagraphs = true;
doc.MailMerge.Execute(new string[]
    {
        "EnvCovHeader",
        "EnvCoverages",
        "AutoCovHeader",
        "AutoCoverages"
    },
    new object[]
    {
        "test1",
        null,
        "test3",
        null
    });
doc.Save("out.docx");

EnvCoverages and AutoCoverages were removed from the document.
Best regards,

Please find the input template and out put doc file.
Values I got from stored procedure are as follows:
«ProducerContactFirstName» «ProducerContactLastName» - NULL
«ProducerContactAddress2» = blank
«PhoneHeading» «UserPhone» «FaxHeading» «UserFax» - blank
You can see how the mergefields are not removed and Producer Contact Address 2 & Phone Heading and Fax Heading line is blank extra line.
Is there a special format with which I need to get data from database?
Thanks
V

Hi

Thank you for additional information. I have refactored your template document and sent to your e-mail. I use the following code for testing:

Document doc = new Document("SuppressLines+In.docx");
doc.MailMerge.RemoveEmptyParagraphs = true;
doc.MailMerge.Execute(
    new string[] {
            "Today",
            "ProducerContactFirstName",
            "ProducerContactLastName",
            "ProducerNumber",
            "ProducerName",
            "ProducerContactAddress",
            "ProducerContactAddress2",
            "ProducerContactCity",
            "ProducerContactState",
            "ProducerContactZipCode",
            "ProducerFax",
            "UserForUnderwriter",
            "PhoneHeading",
            "UserPhone",
            "FaxHeading",
            "UserFax",
            "UserEmail"
        },
    new object[] 
        { 
            "test1", 
            null, 
            null, 
            "test4", 
            "test5", 
            "test6", 
            "", 
            "test8", 
            "test9", 
            "test10", 
            "test11", 
            "test12", 
            "", 
            "", 
            "", 
            "", 
            "test17"
});

doc.Save("out.docx");

Best regards,

Thanks Andrey
Is this happening because the field values you are using are null or “”?
This is how i am getting data & doing the mail merge.

Dim customersDs As DataSet = New DataSet()
Dim sr As StringReader = New StringReader(xmlData)
customersDs.ReadXml(sr)
sr.Dispose()
doc.MailMerge.RemoveEmptyParagraphs = True
doc.MailMerge.Execute(customersDs.Tables("Insured"))

When i see the field values in database i see it either as NULL or blank/empty string. Should i format the data to show as null & “” ?
V

Hi

Thank you for additional information. Please attach also sample data source you are using for executing mail merge. I will check it and provide you more information.
Best regards.