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

Free Support Forum - aspose.com

After mail merge- save the result as individual documents

We have purchased aspose.wrods for .net and it has helped us a great deal to enable us to offer the mail merge functionality in our .net C# web applications. Recently, we got a requirement from our users to save mail merged data into individual documents. I am wondering if anyone has experience in doing this and could share some sample C# code to achieve this.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your help in advance!

Jing Tian

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

Thanks for your request. You just need to perform mailmerege several times. 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.