Formula Calculation Engine in Aspose.Cells
Contents
[
Hide
]
Aspose.Cells - Formula Calculation Engine
The formula calculation engine is embedded in Aspose.Cells. It can not only re-calculate the formula imported from a designer spreadsheet file but also supports to calculate the results of formulas added at runtime.
Java
//Instantiating a Workbook object
Workbook book = new Workbook();
//Obtaining the reference of the newly added worksheet
int sheetIndex = book.getWorksheets().add();
Worksheet worksheet = book.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();
Cell cell = null;
//Adding a value to "A1" cell
cell = cells.get("A1");
cell.setValue(1);
//Adding a value to "A2" cell
cell = cells.get("A2");
cell.setValue(2);
//Adding a value to "A3" cell
cell = cells.get("A3");
cell.setValue(3);
//Adding a SUM formula to "A4" cell
cell = cells.get("A4");
cell.setFormula("=SUM(A1:A3)");
//Calculating the results of formulas
book.calculateFormula();
//Saving the Excel file
book.save(dataDir + "AsposeFormulaEngine.xls");
Download Running Code
Download Sample Code
For more details, visit Formula Calculation Engine.