Calculate Formulas with Golang via C++
Adding Formulas & Calculating Results
Aspose.Cells has an embedded formula calculation engine. Not only can it re-calculate formulas imported from designer templates, but it also supports calculating the results of formulas added at runtime.
Aspose.Cells supports most of the formulas or functions that are part of Microsoft Excel (Read a list of the functions supported by the calculation engine). Those functions can be used through the APIs or designer spreadsheets. Aspose.Cells supports a huge set of mathematical, string, boolean, date/time, statistical, database, lookup, and reference formulas.
Use the GetFormula property or SetFormula(…) methods of the Cell class to add a formula to a cell. When applying a formula, always begin the string with an equal sign (=) as you do when creating a formula in Microsoft Excel and use a comma (,) to delimit function parameters.
To calculate the results of formulas, the user may call the CalculateFormula method of the Workbook class, which processes all formulas embedded in an Excel file. Or, the user may call the CalculateFormula method of the Worksheet class, which processes all formulas embedded in a sheet. Or, the user may also call the Calculate method of the Cell class, which processes the formula of one Cell:
Important to Know for Formulas
Direct Calculation of Formula
Aspose.Cells has an embedded formula calculation engine. As well as calculating formulas imported from a designer file, Aspose.Cells can calculate formula results directly.
Sometimes, you need to calculate formula results directly without adding them into a worksheet. The values of the cells used in the formula already exist in a worksheet, and all you need is to find the result of those values based on some Microsoft Excel formula without adding the formula in a worksheet.
You can use Aspose.Cells' formula calculation engine APIs for Worksheet to calculate the results of such formulas without adding them to the worksheet:
Above code produces the following output:
Value of A1: 20
Value of A2: 30
Result of Sum(A1:A2): 50.0
How to Calculate Formulas Repeatedly
When there are lots of formulas in the workbook and the user needs to calculate them repeatedly with modifying only a small part of them, it may be helpful for performance to enable the formula calculation chain: FormulaSettings.GetEnableCalculationChain().
Important to Know
Advance Topics
- Add Cells to Microsoft Excel Formula Watch Window
- Calculating IFNA function using Aspose.Cells
- Calculation of Array Formula of Data Tables
- Calculation of Excel 2016 MINIFS and MAXIFS functions
- Decrease the Calculation Time of Cell.Calculate method
- Direct calculation of custom function without writing it in a worksheet
- Implement Custom Calculation Engine to extend the Default Calculation Engine of Aspose.Cells
- Returning a Range of Values using AbstractCalculationEngine
- Setting Formula Calculation Mode of Workbook
- Using FormulaText function in Aspose.Cells