Hi,
We are using Aspose Excel to generate reports. The format of the same is attached along.
We are quite satisfied with the results, however when we try to generate the sum of any of the columns of the generated report, we are unable to do so. For example, in the attached sheet, if we are trying to sum the values of J:5 to J:10, we are getting “0”(Zero) as the value. We even tried changing the format of the column to numeric but could not succeed in getting the desired result.
We also have a second issue.
We want to show the negative values in brackets (). Is there any facility to do so?
Kindly help us in this regard.
Warm Regards,
Ramesh J
Hi Ramesh,
How do you set value for column J? If you use the following code:
cell.PutValue(“100”);
The cell value will be a string, not a number. So the sum amount will be 0.
Please change your code to:
cell.PutValue(100);
To show negative values in brackets, you can use cell.Style.Number or cell.Style.Custom to set a desired number format. Or you can directly set the number format in your designer template file.
@RameshJ,
Aspose.Cells is the latest product that has replaced Aspose.Excel which is no more under active development now. This new product supports variety of functions supported by all the latest versions of MS Excel. Here is an example that demonstrates the SUM function using this latest product.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
// Adding a value to "A1" cell
worksheet.Cells["A1"].PutValue(1);
// Adding a value to "A2" cell
worksheet.Cells["A2"].PutValue(2);
// Adding a value to "A3" cell
worksheet.Cells["A3"].PutValue(3);
// Adding a SUM formula to "A4" cell
worksheet.Cells["A4"].Formula = "=SUM(A1:A3)";
// Calculating the results of formulas
workbook.CalculateFormula();
// Get the calculated value of the cell
string value = worksheet.Cells["A4"].Value.ToString();
Console.WriteLine(value);
// Saving the Excel file
workbook.Save("output.xls");
Working with Formulas using Aspose.Cells are described in detail in the following article:
Formulas
The latest free trial version can be downloaded here to test the product features:
Aspose.Cells for .NET (Latest Version)
A runnable solution is available here that can be used to test the new product features without any coding.