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

Free Support Forum - aspose.com

Sum of data in two or more columns

Hi Team,

Please check the attached files SUM.zip (9.2 KB)
I have created a template with three columns COL1 and COL2 and SUM(COL1 + COL2)
Now, how do i add the values of COL1 and COL2 under SUM colum.

Thanks,
Sukesh

@sukesh.kotian

Thanks for your inquiry. You need to add SUM(LEFT) filed in SUM column in the template document. Please find attached updated template with the output document. Hopefully it will help you to accomplish the task.test.zip (17.4 KB)

// Create the Dataset and read the XML.
DataSet dataSet = new DataSet();
dataSet.ReadXml(@"D:\Downloads\SUM\SUM\test.xml");

string fileName = @"D:\Downloads\SUM\SUM\test.rtf";
// Open a template document.
Document doc = new Document(fileName);
doc.MailMerge.UseNonMergeFields = true;

// Execute mail merge to fill the template with data from XML using DataTable.
doc.MailMerge.ExecuteWithRegions(dataSet);

// Save the output document.
doc.Save(@"D:\Downloads\SUM\SUM\test.docx");

@tilal.ahmad

What if there are 5 columns and i just have to calculate sum for 2 columns. Please let me know how do i achieve that?
Also, is there any other aggregate functions i can use. A link to the document would really help.

@sukesh.kotian

Thanks for your feedback. You can specify the required columns in SUM formula. Please find attached sample template and output for your references.test.zip (17.8 KB)

Furthermore, please note Aspose.Words supports almost all the fields those supported by MS Word. So you can use other MS Word supported aggregate functions in Aspose.Words as well. Please let us know If you face any issue in this regard. We will provide you information accordingly.