Skip to content

WASM API

The authoritative TypeScript declarations are shipped as dist/formulon.d.ts. This page summarizes the public shape.

Use the declaration file

When this page and your installed package differ, the dist/formulon.d.ts file in your exact package version is authoritative.

Glossary: status envelope

The Status object returned (directly or as a field) by every fallible WASM call. It carries ok, a numeric status, a human message, and a context field for diagnostics. Cell-level Excel errors are not failed statuses — they are Value objects with kind = Error.

Module

ts
import createFormulon from '@libraz/formulon'

const Module = await createFormulon()

Important module methods:

APIPurpose
Module.evalFormula(formula)One-shot formula evaluation in a fresh workbook
Module.Workbook.createDefault()Workbook with Sheet1
Module.Workbook.createEmpty()Workbook with no sheets
Module.Workbook.loadBytes(bytes)Load an in-memory .xlsx
Module.versionString()Engine version string
Module.statusString(status)Symbolic status description
Module.lastErrorMessage()Last thread-local diagnostic
Module.lastErrorContext()Last thread-local diagnostic context

Result envelopes

Fallible calls return Status or an object containing status.

ts
interface Status {
  ok: boolean
  status: number
  message: string
  context: string
}

Excel cell errors are returned as ValueKind.Error. They are not failed Status values.

Value kinds

ts
enum ValueKind {
  Blank,
  Number,
  Bool,
  Text,
  Error,
  Array,
  Ref,
  Lambda
}

getValue() and evalFormula() return a Value whose kind discriminates the payload. Number values use value.number, Booleans use value.bool, text uses value.text, errors use value.errorCode / value.errorText, arrays use value.array, refs use value.ref, and lambdas use value.lambda.

Workbook lifecycle

ts
const wb = Module.Workbook.loadBytes(bytes)
try {
  if (!wb.isValid()) throw new Error(Module.lastErrorMessage())
  wb.recalc()
  const saved = wb.save()
} finally {
  wb.delete()
}

Always call delete().

Main workbook methods

GroupMethods
SheetsaddSheet, removeSheet, renameSheet, moveSheet, sheetCount, sheetName
CellssetNumber, setBool, setText, setBlank, setFormula, getValue, cellCount, cellAt
Calculationrecalc, partialRecalc, setIterative, setIterativeProgress, calcMode, setCalcMode
ProfilesexcelProfileId, setExcelProfileId
Names/tablesdefinedNameCount, definedNameAt, setDefinedName, tableCount, tableAt
StructureinsertRows, deleteRows, insertCols, deleteCols
Layoutsheet view, protection, row/column layout, styles, merges
Rich workbook datacomments, hyperlinks, data validations, conditional formats, pivot layout, external links
Introspectionprecedents, dependents, functionMetadata, functionNames, spillInfo