The spreadsheet engine of cell formulas (DOM-free): compiles the formula texts of the data ("=SUM(D2:D4)"), keeps a dependency graph (single cells and range nodes) and recalculates only the dependent cells after a change – in topological order (Kahn), cycles (Tarjan) become #CIRC!. No eval, no new Function. Volatile functions (TODAY, NOW, RAND, RANDBETWEEN) are recomputed on every recalculation.

Example

const engine = SheetEngine.fromArrays([
["Laptop", 1299, 2, "=B1*C1"],
["Mouse", 25, 10, "=B2*C2"],
[null, null, null, "=SUM(D1:D2)"],
]);
engine.getValue(2, 3); // 2848

Since

1.1.99

Hierarchy

  • SheetEngine

Constructors

Properties

Methods

  • The new formula texts after rows or columns were inserted or deleted (or cells moved) – the caller writes them (the engine only reads the data). Cells are given at their position after the edit.

    Parameters

    Returns {
        col: number;
        input: string;
        row: number;
    }[]

    changed formula texts

  • Evaluates a formula once (not stored), e.g. for a formula bar preview.

    Parameters

    • source: string

      the formula ("=SUM(D2:D4)", the = is optional)

    • Optional at: readonly [number, number]

      the cell it is evaluated in (for [field])

    Returns unknown

    the result

    Example

    engine.evaluate("=SUM(D2:D4)");   // 3895
    
  • The formula cells that read a cell directly.

    Parameters

    • row: number

      physical row

    • col: number

      column

    Returns [number, number][]

    row and column of each dependent

  • The value of a cell: the result of its formula or its data value (Date for dates, a FormulaError for an error, '=… without the quote).

    Parameters

    • row: number

      physical row (0-based)

    • col: number

      column (0-based)

    Returns unknown

    the value

  • True if the cell holds a formula.

    Parameters

    • row: number

      physical row

    • col: number

      column

    Returns boolean

    true for a formula cell

  • An engine over a 2-D array (rows of cells) – without a table.

    Parameters

    • data: unknown[][]

      the cells; formula texts start with =

    • Optional options: Partial<CellFormulaOptionsIf>

      own functions and limits

    Returns SheetEngine

    the engine, already calculated

    Example

    SheetEngine.fromArrays([[1, 2, "=A1+B1"]]).getValue(0, 2);   // 3