Formula calculation
The Formulas plugin adds spreadsheet-style calculation to Handsontable, powered by HyperFormula. It supports ~400 built-in functions, cross-sheet references, named expressions, and custom function implementations.
Basic multi-sheet example
You can use formulas in a single-sheet mode or with multiple Handsontable instances with cross-sheet references.
Double click on a cell to open the editor and preview the formula.
Data grid example
This example is more typical of data grids than spreadsheets. Calculations are present in two places – in column “Total due (fx)”, and in the summary row at the bottom.
Initialization methods
The formulas option accepts either the HyperFormula class or an already-created HyperFormula
instance. Choose the pattern that matches your use case.
All patterns require importing HyperFormula:
import { HyperFormula } from 'hyperformula';See HyperFormula’s installation docs for alternative installation methods (CDN, UMD, etc.).
// create an external HyperFormula instanceconst hyperformulaInstance = HyperFormula.buildEmpty({ // initialize it with the `'internal-use-in-handsontable'` license key licenseKey: 'internal-use-in-handsontable',});Pass the HyperFormula class/instance to Handsontable
or
Single Handsontable instance with an external HyperFormula instance
Multiple independent Handsontable instances
Multiple Handsontable instances with an external shared HyperFormula instance
Available options and methods
For the full list of configuration options and plugin methods, see the
Formulas API reference.
Available functions
The plugin inherits all calculation capabilities from HyperFormula. The complete function reference (386 functions across Math, Engineering, Statistical, Financial, Logical, and other categories) is in the HyperFormula built-in functions docs.
afterFormulasValuesUpdate hook
This hook fires whenever the calculation engine recomputes cell values - including cells that
changed directly and all dependent formula cells. Use it to react to recalculations outside of the
normal afterChange flow.
Named expressions
A named expression assigns a human-friendly label to a value or formula. Once defined, the name can be used anywhere in cell formulas across the workbook - the same way a cell reference or constant would be. This is useful for shared constants, computed ranges, or any value you want to reference by a meaningful name instead of repeating a formula.
The expression field accepts:
- A number (e.g.
100) or string (e.g.'"My Label"'- note the inner quotes, which are part of HyperFormula formula syntax for string literals). - A formula string starting with
=, using the same syntax as cell formulas.
Plain values can be registered directly in the namedExpressions config array:
formulas: { engine: HyperFormula, namedExpressions: [ { name: 'ADDITIONAL_COST', expression: 100 }, ],}Range-formula expressions (those that reference cells with Sheet1!...) must be registered on
a pre-built HyperFormula instance after the sheet has been created. Registering them via the config
array causes a #REF! error because the sheet does not exist yet at that point in the
initialization sequence:
const hfInstance = HyperFormula.buildEmpty({ licenseKey: 'internal-use-in-handsontable',});
hfInstance.addSheet('Sheet1');hfInstance.addNamedExpression('Q1_TOTAL', '=SUM(Sheet1!$B$1:$B$3)');hfInstance.addNamedExpression('COMBINED', '=SUM(Sheet1!$A$1:$A$3)+SUM(Sheet1!$B$1:$B$3)');
new Handsontable(container, { formulas: { engine: hfInstance, sheetName: 'Sheet1' }, // ...});Demo: plain-value named expression
The example below registers ADDITIONAL_COST as a plain number. Cell formulas in column D add that
constant to each base price. The input below the grid lets you replace the expression at runtime
using changeNamedExpression().
Demo: formula-based named expressions
The example below registers Q1_TOTAL and Q2_TOTAL as range-sum formulas on a pre-built
HyperFormula instance. The “Totals” row references those names directly as =Q1_TOTAL and
=Q2_TOTAL.
For more information about named expressions, refer to the HyperFormula named expressions docs.
View the explainer video
Known limitations
- Using the
IndexMapperAPI to programmatically move rows or columns that contain formulas is not supported. Instead, use theManualRowMoveorManualColumnMoveAPIs. - Formulas don’t support
getSourceData(), as this method operates on source data (using physical indexes), whereas formulas operate on visual data (using visual indexes). - Formulas don’t support nested data, i.e., when Handsontable’s
datais set to an array of nested objects.
HyperFormula version support
Different versions of Handsontable support different versions of HyperFormula.
To find out which HyperFormula version to use, see the table below:
| Handsontable version | HyperFormula version |
|---|---|
8.x.x and lower | No HyperFormula support |
9.x.x | 0.6.2 |
10.x.x | ^1.2.0 |
11.x.x | ^1.2.0 |
12.x.x | ^2.0.0 |
13.x.x | ^2.4.0 |
14.x.x | ^2.4.0 |
14.3.x - 15.0.x | ^2.6.2 |
15.1.x and higher | ^3.0.0 |
Related articles
HyperFormula documentation
Related blog articles
Configuration options
Hooks
Plugins
Result
After setting up the Formulas plugin with a HyperFormula engine, cells that contain a formula (starting with =) are evaluated automatically. Editing a cell updates all dependent formula cells in real time, and cross-sheet references stay in sync across linked Handsontable instances.