Hi Janath,
Thanks for your inquiry.
I have attached a template Word document (SumAvgExample.docx) here for your reference. This document contains a “mail merge with regions” Row that is duplicated the number of times the DataTable has Rows in it. As shown in following example code, after the MailMerge.ExecuteWithRegions method call, the UpdateFields method of Aspose.Words calculates the values of SUM and AVERAGE formula fields which are contained inside the second Row in the template document.
Document doc = new Document(MyDir + @"SumAvgExample.docx");
doc.MailMerge.ExecuteWithRegions(GetDataTable());
doc.UpdateFields();
doc.Save(MyDir + @"16.1.0.docx");
private static DataTable GetDataTable()
{
DataTable dataTable = new DataTable("tbl");
dataTable.Columns.Add(new DataColumn("mf1"));
dataTable.Columns.Add(new DataColumn("mf2"));
DataRow dataRow;
for (int i = 1; i < 5; i++)
{
dataRow = dataTable.NewRow();
dataRow[0] = i;
dataRow[1] = i;
dataTable.Rows.Add(dataRow);
}
return dataTable;
}
Hope, this helps.
Best regards,
Edit: SumAvgExample.zip (9.7 KB) and output.zip (14.5 KB)