API reference
Cells & values
Cell shape, formula helpers, inline rich-text composition.
Cell
src/cell/cell.ts# bindValue function
src/cell/cell.ts:110"Smart" setter: infers the cell value from a JS runtime value. - `string` starting with `=` → formula - `string` matching an Excel error token → error variant - other primitives / Date / null pass through verbatim Intentionally not the default — explicit is clearer for typed code, and inferring on every write costs measurable time on the worksheet write hot path.
function bindValue(c: Cell, value: string | number | boolean | Date | null): voidParameters
| Name | Type | Description |
|---|---|---|
c | Cell | |
value | string | number | boolean | Date | null |
Returns
void
# cellValueAsBoolean function
src/cell/cell.ts:364Coerce a CellValue to `boolean | undefined`. Booleans pass through; `'TRUE'` / `'true'` and `'FALSE'` / `'false'` (case-insensitive) parse to true / false; numbers yield `false` for 0 and `true` for any other finite value (matching Excel's truthy-number coercion); formula cells return their cached boolean if any. Everything else (null, Date, error, duration, rich-text, non-bool strings) yields `undefined`.
function cellValueAsBoolean(v: CellValue): boolean | undefinedParameters
| Name | Type | Description |
|---|---|---|
v | CellValue |
Returns
boolean | undefined
# cellValueAsDate function
src/cell/cell.ts:388Coerce a CellValue to a `Date` when one is meaningful. Pass-through for `Date`-typed values; ISO-8601 strings (anything `new Date(s)` parses to a finite time) round-trip; durations are interpreted as `new Date(ms)`. Numbers, booleans, formulas, errors, rich text, and null all return `undefined` — this helper does **not** apply the Excel-serial-to-Date conversion (use `excelToDate` for that).
function cellValueAsDate(v: CellValue): Date | undefinedParameters
| Name | Type | Description |
|---|---|---|
v | CellValue |
Returns
Date | undefined
# cellValueAsNumber function
src/cell/cell.ts:407Coerce a CellValue to a number when one is meaningful. Booleans yield 0/1; numeric strings parse via `Number(s)`; rich-text concats then parses; formulas with a numeric cached value pass through. Returns `undefined` when there's no sensible numeric reading (text strings, errors, dates, durations, null, empty).
function cellValueAsNumber(v: CellValue): number | undefinedParameters
| Name | Type | Description |
|---|---|---|
v | CellValue |
Returns
number | undefined
# cellValueAsPrimitive function
src/cell/cell.ts:433Map a CellValue to the most natural JS primitive for display / export. Unlike `cellValueAsString`/`cellValueAsNumber`/etc., which each force a single target type and return `undefined` when the value can't be coerced, this returns whatever primitive best represents the union variant: - `null` → `null` - `string` / `number` / `boolean` / `Date` → passthrough - rich text → joined run text (`string`) - formula → recursive on `cachedValue` (`null` when uncached) - error → error code (`string`) - duration → `ms` (`number`)
function cellValueAsPrimitive(v: CellValue): string | number | boolean | Date | nullParameters
| Name | Type | Description |
|---|---|---|
v | CellValue |
Returns
string | number | boolean | Date | null
# cellValueAsString function
src/cell/cell.ts:340Coerce a CellValue to its plain-string display form. Numbers / booleans convert via `String`; rich text concatenates run text; formulas yield the cached value (or empty string when uncached); errors yield their Excel token; durations yield `"<ms> ms"` with no formatting; Dates yield `Date.toISOString()`; `null` yields `""`. Pass `opts.dateFormat` to override the Date renderer (e.g. a locale-specific format) and `opts.emptyText` to substitute a different placeholder for `null` cells.
function cellValueAsString(v: CellValue, opts?: CellValueAsStringOptions): stringParameters
| Name | Type | Description |
|---|---|---|
v | CellValue | |
opts? | CellValueAsStringOptions |
Returns
string
# getCachedFormulaValue function
src/cell/cell.ts:296Get the cached value Excel last computed for a formula cell, or `undefined` for non-formula / uncached cells. Useful for `data_only` read paths that want the displayed result without re-evaluating.
function getCachedFormulaValue(c: Cell): string | number | boolean | undefinedParameters
| Name | Type | Description |
|---|---|---|
c | Cell |
Returns
string | number | boolean | undefined
# getCoordinate function
src/cell/cell.ts:88Format a Cell's coordinate as the canonical "A1" string.
function getCoordinate(c: Cell): stringParameters
| Name | Type | Description |
|---|---|---|
c | Cell |
Returns
string
# getFormulaText function
src/cell/cell.ts:287Get the formula text from a formula-bearing cell, or `undefined` for non-formula cells. Equivalent to: isFormulaValue(c.value) ? c.value.formula : undefined but spares callers the type-narrow + member access.
function getFormulaText(c: Cell): string | undefinedParameters
| Name | Type | Description |
|---|---|---|
c | Cell |
Returns
string | undefined
# isDurationValue function
src/cell/cell.ts:318True iff `v` is the duration variant.
function isDurationValue(v: CellValue): v is { kind: "duration"; ms: number }Parameters
| Name | Type | Description |
|---|---|---|
v | CellValue |
Returns
v is { kind: "duration"; ms: number }
# isEmptyCell function
src/cell/cell.ts:263Returns true iff the cell has no content.
function isEmptyCell(c: Cell): booleanParameters
| Name | Type | Description |
|---|---|---|
c | Cell |
Returns
boolean
# isErrorCell function
src/cell/cell.ts:278Returns true iff the cell holds an Excel error value (`#REF!`, `#NAME?`, …).
function isErrorCell(c: Cell): booleanParameters
| Name | Type | Description |
|---|---|---|
c | Cell |
Returns
boolean
# isErrorValue function
src/cell/cell.ts:313True iff `v` is the error variant.
function isErrorValue(v: CellValue): v is { code: ExcelErrorCode; kind: "error" }Parameters
| Name | Type | Description |
|---|---|---|
v | CellValue |
Returns
v is { code: ExcelErrorCode; kind: "error" }
# isFormulaCell function
src/cell/cell.ts:253True iff `c.value` is the formula variant.
function isFormulaCell(c: Cell): booleanParameters
| Name | Type | Description |
|---|---|---|
c | Cell |
Returns
boolean
# isFormulaValue function
src/cell/cell.ts:303True iff `v` is the formula variant.
function isFormulaValue(v: CellValue): v is FormulaValueParameters
| Name | Type | Description |
|---|---|---|
v | CellValue |
Returns
v is FormulaValue
# isMergedCell function
src/cell/cell.ts:273Type guard for `MergedCell` — true iff the cell is a placeholder for a merged-range covered cell (the top-left of a merged range holds the value; the rest are `MergedCell`). Use this to filter merge-placeholders out of value-walking loops.
function isMergedCell(c: Cell): c is MergedCellParameters
| Name | Type | Description |
|---|---|---|
c | Cell |
Returns
c is MergedCell
# isRichTextCell function
src/cell/cell.ts:258True iff `c.value` is the rich-text variant.
function isRichTextCell(c: Cell): booleanParameters
| Name | Type | Description |
|---|---|---|
c | Cell |
Returns
boolean
# isRichTextValue function
src/cell/cell.ts:308True iff `v` is the rich-text variant.
function isRichTextValue(v: CellValue): v is { kind: "rich-text"; runs: RichText }Parameters
| Name | Type | Description |
|---|---|---|
v | CellValue |
Returns
v is { kind: "rich-text"; runs: RichText }
# makeCell function
src/cell/cell.ts:82Build a fresh Cell. Validates coordinates against the OOXML grid bounds.
function makeCell(row: number, col: number, value?: CellValue, styleId?: number): CellParameters
| Name | Type | Description |
|---|---|---|
row | number | |
col | number | |
value? = null | CellValue | |
styleId? = 0 | number |
Returns
Cell
# makeDurationValue function
src/cell/cell.ts:245Build a `{ kind: 'duration', ms }` cell value.
function makeDurationValue(ms: number): { kind: "duration"; ms: number }Parameters
| Name | Type | Description |
|---|---|---|
ms | number |
Returns
{ kind: "duration"; ms: number }
# makeErrorValue function
src/cell/cell.ts:237Build a `{ kind: 'error', code }` cell value.
function makeErrorValue(code: ExcelErrorCode): { code: ExcelErrorCode; kind: "error" }Parameters
| Name | Type | Description |
|---|---|---|
code | ExcelErrorCode |
Returns
{ code: ExcelErrorCode; kind: "error" }
# setArrayFormula function
src/cell/cell.ts:140Array (CSE) formula spanning a `ref` range.
function setArrayFormula(c: Cell, ref: string, formula: string, opts?: { cachedValue?: string | number | boolean }): voidParameters
| Name | Type | Description |
|---|---|---|
c | Cell | |
ref | string | |
formula | string | |
opts? | { cachedValue?: string | number | boolean } |
Returns
void
# setCellValue function
src/cell/cell.ts:96Direct value setter. No type inference, no validation beyond the union — the caller is in charge. Use bindValue for the "do what I mean" path.
function setCellValue(c: Cell, value: CellValue): voidParameters
| Name | Type | Description |
|---|---|---|
c | Cell | |
value | CellValue |
Returns
void
# setDataTableFormula function
src/cell/cell.ts:215Set a data-table formula on a cell. Preserves all the dt-specific attributes so the writer can re-emit `<f t="dataTable" r1="..." />` verbatim and Excel keeps treating the cell as a Data Table cell.
function setDataTableFormula(c: Cell, formula: string, opts: DataTableFormulaOpts): voidParameters
| Name | Type | Description |
|---|---|---|
c | Cell | |
formula | string | |
opts | DataTableFormulaOpts |
Returns
void
# setFormula function
src/cell/cell.ts:129Plain `=A1+B1` style formula. Cached value is optional but recommended for round-trip.
function setFormula(c: Cell, formula: string, opts?: { cachedValue?: string | number | boolean }): voidParameters
| Name | Type | Description |
|---|---|---|
c | Cell | |
formula | string | |
opts? | { cachedValue?: string | number | boolean } |
Returns
void
Rich text
src/cell/rich-text.ts# makeRichText function
src/cell/rich-text.ts:51function makeRichText(runs: readonly (TextRun | { font?: InlineFont; text: string })[]): RichTextParameters
| Name | Type | Description |
|---|---|---|
runs | readonly (TextRun | { font?: InlineFont; text: string })[] |
Returns
RichText
# makeTextRun function
src/cell/rich-text.ts:44function makeTextRun(text: string, font?: InlineFont): TextRunParameters
| Name | Type | Description |
|---|---|---|
text | string | |
font? | InlineFont |
Returns
TextRun
# richTextToString function
src/cell/rich-text.ts:60Concatenate the plain-text content of a rich-text value (rich-text read paths often want the raw text without formatting).
function richTextToString(rt: RichText): stringParameters
| Name | Type | Description |
|---|---|---|
rt | RichText |
Returns
string