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

Free Support Forum - aspose.com

Calculate SUM & AVERAGE Formula Fields in Word DOCX Document during Mail Merge using C# Example

@awais.hafeez Can you share the example. I cant see the example.

@kalrapiyush,

Please see these input/output Word DOCX documents (SumAvgExample.zip (18.7 KB)) and try running the following C# code:

Document doc = new Document("E:\\Temp\\SumAvgExample (1)\\SumAvgExample.docx");
doc.MailMerge.ExecuteWithRegions(GetDataTable());
doc.UpdateFields();
doc.Save("E:\\Temp\\SumAvgExample (1)\\20.5.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.