Free Support Forum - aspose.com

Aspose Word Template MailMerge

Hello,
I am creating a word document template using mailmerge.
this attach template i have 2 column value in my datatable c#.
i try to merge datatable value to my mailmerge template.
but not created this attach type template.
so please provide the solution how to mailmerge this type of template using Aspose.word c#.

I Want to this type output aspose word template mailmerge c#.png (26.6 KB)

@YogeshAsopa,

Please see these input/output word documents (ExecuteWithRegions-template.docx and 18.8.docx) and try running the following code:
ExecuteWithRegions-template.zip (18.6 KB)

DataTable dataTable = new DataTable("tbl");

dataTable.Columns.Add(new DataColumn("col1"));
dataTable.Columns.Add(new DataColumn("col2"));

DataRow dataRow;
for (int i = 1; i < 5; i++)
{
    dataRow = dataTable.NewRow();
    dataRow[0] = "column 1_" + i;
    dataRow[1] = "column 2_" + i;

    dataTable.Rows.Add(dataRow);
}

Document doc = new Document("D:\\Temp\\ExecuteWithRegions-template.docx");
doc.MailMerge.ExecuteWithRegions(dataTable);

doc.Save("D:\\temp\\18.8.docx");

Hope, this helps.