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

Free Support Forum - aspose.com

Outputing multiple documents clarification

So in the Dinner Invitation demo I expect that there are multiple documents that are created. Does the MailMerge.Execute method have to be called for each new row to produce a new document?
This message was posted using Page2Forum from Simple Mail Merge Explained - Aspose.Words for .NET and Java

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

Thanks for your request. Yes, you should execute mail merge for each record in your data source. Please see the following code:

//Create dummy datasource

DataTable data = new DataTable();

data.Columns.Add("FirstName");

data.Columns.Add("LastName");

data.Columns.Add("City");

data.Columns.Add("Company");

//add dummy data

data.Rows.Add(new object[] { "Den", "Smith", "<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />London", "Apple" });

data.Rows.Add(new object[] { "Steve", "Martin", "Berlin", "Stern" });

data.Rows.Add(new object[] { "Nina", "Burn", "Tallin", "IBM" });

//Open template document

Document doc = new Document(@"Test014\in.doc");

int counter = 0;

//Loop though all record in our datasource

foreach (DataRow row in data.Rows)

{

//Clone template

Document temp = (Document)doc.Clone(true);

//Execute mail merge

temp.MailMerge.Execute(row);

//Save document

temp.Save(string.Format(@"Test014\out_{0}.doc", counter));

counter++;

}

Hope this helps.

Best regards.

Thanks for the feedback. The example is very helpful.

I noticed that the API’s MaillMerge.Execute also accepts System.Data.DataTables. Could you provide a little sample using DataTables?



Thanks

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

Thanks for your request. You can find such example in the documentation. Please see the following link:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.reporting.mailmerge.execute_overload_3.html

Best regards,