We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MailMerge with DataTable generating a document with repeating data

Hi. I am a new user of the latest version of Aspose.Words.


I have a DataTable that I am using as my source data for a Mail Merge. I need individual letters for each record in the table as well as one combined document of all letters. If I iterate through the rows in the DataTable, calling the MailMerge.Execute(DataRow) method each time, it is generating the letters correctly from the template. However, when I attempt to generate the combined document via MailMerge.Execute(DataTable), it is generating a document with the correct number of pages based on the number of rows in the table, but the data is duplicated on each page (same name and address appears on every page). Is there some setting that I am missing?

Thanks, Aaron Carpenter

Hi Aaron,


Thanks for your interest in Aspose.Words.

When you perform a simple mail merge operation using MailMerge.Execute method, the whole template document is repeated for each data row in the data source. When mail merge reaches end of the main document and there are still more rows in the DataTable, it copies entire content of the main document and appends it to the end of the destination document using a section break as a separator. I would suggest you please refer to the following articles for details:

http://www.aspose.com/docs/display/wordsnet/Simple+Mail+Merge+Explained
http://www.aspose.com/docs/display/wordsnet/How+to++Execute+Simple+Mail+Merge
http://www.aspose.com/docs/display/wordsnet/How+to++Produce+Multiple+Documents+during+Mail+Merge

Please let me know if I can be of any further assistance.

Best regards,

Thanks for the reply. I have checked these and still have the issue

I dug into this a little more. My test case has a DataTable with 1,000 records and the template is a single page letter. When I execute the merge passing in the table, the generated document has 1,000 pages as expected, however it is 1,000 pages of the letter with the data from the last row in the data table. I tried this with two different templates and got the same behavior.

Hi Aaron,


Thanks for your inquiry. To ensure a timely and accurate response, it would be great if you please create a standalone runnable simple application (for example a Console Application project) that helps us reproduce your problem on our end and attach it here for testing. As soon as you get this simple application ready, we’ll start investigation into your issue and provide you more information. Also, please attach the template Word document and output document showing the undesired behavior here for testing.

Best regards,

Thanks for your reply. I have attached the requested data.



The “test_documents.zip” file has the generated documents. You will see that four of the files are individual letters and the “combined” doc should be all 4 letters together. However, it is actually 4 copies of the last letter.



This is any extremely urgent request. I need an answer ASAP, early on Monday if possible. How much would is cost to upgrade this to a priority request if needed?



Thanks, Aaron

Hi Aaron,


Thanks for the additional information. Please fix the following lines of code to generate a correct “combined.docx”.

Console.WriteLine(“Generating
Group Document”
);

workingGroupDoc = templateDoc.Clone();

string workingGroupPath = Path.Combine(@"C:\temp\test_doc\", "combined.docx");

workingGroupDoc.MailMerge.CleanupOptions = Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveContainingFields;

workingGroupDoc.MailMerge.Execute(entityData);

workingGroupDoc.MailMerge.DeleteFields();

//Save doc file.

workingGroupDoc.Save(workingGroupPath);


I hope, this helps.

Best regards,

Ahhh. THANK YOU, THANK YOU!!! I knew that I must be missing something. Now that you pointed it out, I understand why it was generating the file in the way that it was.

One other issue now. I have a numbered list on one template. The numbers aren’t restarting on each page, they just keep going up. is there a setting for this?

Hi Aaron,


Thanks for your inquiry. We will provide an option in API to control whether to restart or continue list numbering during mail merge in future. Your request has been linked to the appropriate “feature” in our issue tracking system (WORDSNET-1860) and you will be notified as soon as it is available. Sorry for the inconvenience.

Best regards,

A post was split to a new topic: Clone Word Document and then Execute MailMerge (Regions)

The issues you have found earlier (filed as WORDSNET-1860) have been fixed in this Aspose.Words for .NET 19.12 update and this Aspose.Words for Java 19.12 update.