This page covers a next version of Handsontable, and is not published yet.

This page covers a non-latest version of Handsontable.

# Formulas

# Description

This plugin allows you to perform Excel-like calculations in your business applications. It does it by an integration with our other product, HyperFormula (opens new window), which is a powerful calculation engine with an extensive number of features.

To test out HyperFormula, see this guide.

# Options

# formulas

Source code (opens new window)

formulas.formulas : object

The formulas option configures the Formulas plugin.

The Formulas plugin uses the HyperFormula (opens new window) calculation engine. To install HyperFormula (opens new window), read the following:

You can set the formulas option to an object with the following properties:

Property Possible values
engine HyperFormula |
A HyperFormula (opens new window) instance |
A HyperFormula configuration (opens new window) object
sheetId A number
sheetName A string

Read more:

Default: undefined Example

// either add the `HyperFormula` class
formulas: {
  // set `engine` to `HyperFormula`
  engine: HyperFormula,
  sheetId: 1,
  sheetName: 'Sheet 1'
}

// or, add a HyperFormula instance
// initialized with the `'internal-use-in-handsontable'` license key
const hyperformulaInstance = HyperFormula.buildEmpty({
  licenseKey: 'internal-use-in-handsontable',
});

formulas: {
  // set `engine` to a HyperFormula instance
  engine: hyperFormulaInstance,
  sheetId: 1,
  sheetName: 'Sheet 1'
}

// or, add a HyperFormula configuration object
formulas: {
  // set `engine` to a HyperFormula configuration object
  engine: {
    hyperformula: HyperFormula // or `engine: hyperFormulaInstance`
    leapYear1900: false,       // this option comes from HyperFormula
    // add more HyperFormula configuration options
  },
  sheetId: 1,
  sheetName: 'Sheet 1'
}

// use the same HyperFormula instance in multiple Handsontable instances

// a Handsontable instance `hot1`
formulas: {
  engine: HyperFormula,
  sheetId: 1,
  sheetName: 'Sheet 1'
}

// a Handsontable instance `hot2`
formulas: {
  engine: hot1.getPlugin('formulas').engine,
  sheetId: 1,
  sheetName: 'Sheet 1'
}

# Members

# engine

Source code (opens new window)

formulas.engine : HyperFormula | null

The engine instance that will be used for this instance of Handsontable.

# sheetId

Source code (opens new window)

formulas.sheetId : number | null

HyperFormula's sheet id.

# sheetName

Source code (opens new window)

formulas.sheetName : string | null

HyperFormula's sheet name.

# Methods

# addSheet

Source code (opens new window)

formulas.addSheet([sheetName], [sheetData]) ⇒ boolean | string

Add a sheet to the shared HyperFormula instance.

Param Type Description
[sheetName] string
null
optional The new sheet name. If not provided (or a null is passed), will be auto-generated by HyperFormula.
[sheetData] Array optional Data passed to the shared HyperFormula instance. Has to be declared as an array of arrays - array of objects is not supported in this scenario.

Returns: boolean | string - false if the data format is unusable or it is impossible to add a new sheet to the engine, the created sheet name otherwise.

# destroy

Source code (opens new window)

formulas.destroy()

Destroys the plugin instance.

# disablePlugin

Source code (opens new window)

formulas.disablePlugin()

Disables the plugin functionality for this Handsontable instance.

# enablePlugin

Source code (opens new window)

formulas.enablePlugin()

Enables the plugin functionality for this Handsontable instance.

# getCellType

Source code (opens new window)

formulas.getCellType(row, column, [sheet]) ⇒ string

Get the cell type under specified visual coordinates.

Param Type Description
row number Visual row index.
column number Visual column index.
[sheet] number optional The target sheet id, defaults to the current sheet.

Returns: string - Possible values: 'FORMULA' | 'VALUE' | 'ARRAYFORMULA' | 'EMPTY'.

# isEnabled

Source code (opens new window)

formulas.isEnabled() ⇒ boolean

Checks if the plugin is enabled in the handsontable settings. This method is executed in Hooks#beforeInit hook and if it returns true than the Formulas#enablePlugin method is called.

# isFormulaCellType

Source code (opens new window)

formulas.isFormulaCellType(row, column, [sheet]) ⇒ boolean

Returns true if under specified visual coordinates is formula.

Param Type Description
row number Visual row index.
column number Visual column index.
[sheet] number optional The target sheet id, defaults to the current sheet.

# switchSheet

Source code (opens new window)

formulas.switchSheet(sheetName)

Switch the sheet used as data in the Handsontable instance (it loads the data from the shared HyperFormula instance).

Param Type Description
sheetName string Sheet name used in the shared HyperFormula instance.
Last Updated: Apr 19, 2024