Sum all the values of a particular column in a worksheet in .NET

Hi,


I have a simple query. In an excel worksheet when I select a column suppose column B, I get the sum of all the numerical values present in that column. Now how do I do that with the help of Aspose.Cells?

Regards,
Neel

Hi,


You may try, see the following sample code for your reference, the comments are added for your help.

Sample code:

Workbook wb = new Workbook(“e:\test\Book1.xls”);

Worksheet sheet1 = wb.Worksheets[0];

Cells cells = sheet1.Cells;

//Suppose we want to sum the Col A,

//We will set the formula for it

cells[“B1”].Formula = “=SUM(A:A)”;

//Calculate the formula(s)

wb.CalculateFormula();

//Get the SUM

double tsum = cells[“B1”].DoubleValue;

//Show it on the screen

MessageBox.Show(tsum.ToString());

//Now delete the B1 formula if you want.

cells[“B1”].PutValue(cells[“B1”].DoubleValue);

wb.Save(“e:\test2\out_Book.xls”);

Thank you.