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; // 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.