Skip to content
Sheetwrite

@sheetwrite/core/functions

functionsAddonfunction

Report a problem

On this page

The custom functions add-on. Each function is a synchronous JavaScript function that formulas can call. functions apply to every grid created after initSheetwrite; grid-specific functions go in createGrid(host, { addons: { functions: [...] } }) and apply to that grid only. A grid-specific function replaces an init function with the same name in that grid. Functions register when the grid is created; there is no later add or remove.

A function receives each argument as a scalar, or as row arrays for a block of more than one cell, and returns a number, text, boolean, or null for an empty result. A thrown error or any other result shows #VALUE!. The function must not read calculated cells or change the store: calls that need the engine throw a blocked error. Snapshots keep only formula text.

createGrid throws a SheetwriteError with code invalid-function when a name is a built-in function, a cell reference or not a function name, or the metadata is malformed, and optional-backend-unavailable on the default engine, because only the full engine (@sheetwrite/formulas) has host functions.

Declaration

function functionsAddon(
functions?: readonly FormulaFunctionDefinition[],

Parameters

functions?: readonly FormulaFunctionDefinition[]optional

The functions to add to every grid created after initSheetwrite.

Returns

The add-on to pass in initSheetwrite({ addons }).

See also