Update SUM & AVG Function Fields in Word DOCX Table during Mail Merge using C# .NET


I am new to ASPOSE and would like know whether below feature can be implemented.

  1. Customer provide the doc template which can have place holders. For ex: place holders for populate table.
  2. Customer send the data and our system needs to render the report with table data.
  3. Table may have aggregate functions like SUM or AVG.

Appreciate if someone can advise on this.


Hi Janath,

Thanks for your inquiry. Yes, you can meet these requirements using Aspose.Words for Java API. Please refer to the following section of documentation:

Mail Merge and Reporting

Aspose.Words also supports SUM, AVG and many other fields. Please let us know if we can be of any further assistance.

Best regards,

Hi Awais,

Thanks for the reply.

is it possible to provide concrete example for SUM or AVE functions? For example, I wanted to append a new row to a table which shows Total of particular column.

Appreciate your feedback. thanks


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.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;
    return dataTable;

Hope, this helps.

Best regards,
Edit: SumAvgExample.zip (9.7 KB) and output.zip (14.5 KB)

3 posts were split to a new topic: SUM and AVERAGE fields - MailMerge.ExecuteWithRegions

A post was split to a new topic: Calculate SUM & AVERAGE Formula Fields in Word DOCX Document during Mail Merge using C# Example

2 posts were merged into an existing topic: Calculate SUM & AVERAGE Formula Fields during Mail Merge using C# Example