Free Support Forum - aspose.com

Blank Lines and merge fields issue in aspose words

We are doing the Mail merge in Labels .

If the data on any field is not coming then it is leaving the Blank line in it . Check the attachment "result-2.doc" . The 1st and 5th label has blank lines .

We even used "RemoveEmptyParagraphs" but still it is showing blanks .

Also we want the Blank Labels which do not have data should not come with Merge Fields . That means if the template have 10 labels and the Datasource is returning only 6 lables , then the rest 4 should be blank .

But in the attached doc it shows the Merge fields for them

Below is the code:

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

// Open an existing document.

if (File.Exists(filename))

doc = new Document(filename);

else

doc = new Document(defaultfilename);

doc.MailMerge.RemoveEmptyParagraphs = true;

// Fill the fields in the document with user data.

doc.MailMerge.Execute(dt);

// Send the document in Word format to the client browser.

doc.Save(Globals.EventAttendeesPrintDocName, SaveFormat.Doc, SaveType.OpenInBrowser, Response);

where filename is the template file(Label Template.docx) on which MailMerge to run.

Hi

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

Thanks for your inquiry. I cannot reproduce the problem with blank lines using the latest version of Aspose.Words. If you would like to delete all empty mergefields you can try using the following code before saving:

doc.MailMerge.DeleteFields();

Hope this helps.

Best regards,

The problem is same with the new version also . The files I have provided above were done in new version.

Also when we used
doc.MailMerge.DeleteFields();

The Created document of Labels was blank . Please advise we with the set of code sample how to use this .
Our code is as above .

Our aim is that for those records whose data is not coming in case of Labels the merge fields should not be there .
Like we have a data of 10 labels and the doc template has 15 labels then the created doc should only be of 10 labels and rest should be blank .


Hi

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

Thank you for additional information. Please try the following code:

// Open an existing document.

Document doc = new Document(@"Test001\template.docx");

doc.MailMerge.RemoveEmptyParagraphs = true;

doc.MailMerge.Execute(GetTestInfo());

doc.MailMerge.DeleteFields();

doc.Save(@"Test001\out.doc");

private DataTable GetTestInfo()

{

// Create data table

DataTable table = new DataTable("Info");

table.Columns.Add("contact_name");

table.Columns.Add("account_name");

table.Columns.Add("address_line1");

table.Columns.Add("address_line2");

table.Columns.Add("suburb");

table.Columns.Add("state");

table.Columns.Add("postcode");

table.Columns.Add("country");

// Add some dummy data.

table.Rows.Add(new object[] { "Andrey", "Lirik", "", "", "", "State", "66000", "Ukraine" });

table.Rows.Add(new object[] { "Andrey1", "Lirik1", "Address11", "Address21", "Suburb1", "State1", "66001", "Ukraine" });

table.Rows.Add(new object[] { "Andrey2", "", "Address12", "Address22", "Suburb2", "State2", "", "" });

table.Rows.Add(new object[] { "Andrey3", "Lirik3", "Address13", "Address23", "Suburb3", "State3", "66003", "Ukraine" });

return table;

}

This code works exactly as you need. Please let me know in case of any issues.

Best regards,