API reference
Worksheet
Worksheet shape and the cell / row / column helpers built on top of it.
Worksheet
src/worksheet/worksheet.ts# addCellWatch function
src/worksheet/worksheet.ts:2163Pin a cell to the Watch Window. Returns the pushed entry.
function addCellWatch(ws: Worksheet, watch: CellWatch): CellWatchParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
watch | CellWatch |
Returns
CellWatch
# addConditionalFormatting function
src/worksheet/worksheet.ts:2143Append a conditional formatting block.
function addConditionalFormatting(ws: Worksheet, cf: ConditionalFormatting): ConditionalFormattingParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
cf | ConditionalFormatting |
Returns
ConditionalFormatting
# addDataValidation function
src/worksheet/worksheet.ts:1984Append a DataValidation entry.
function addDataValidation(ws: Worksheet, dv: DataValidation): DataValidationParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
dv | DataValidation |
Returns
DataValidation
# addIgnoredError function
src/worksheet/worksheet.ts:2176Append an ignored-error region.
function addIgnoredError(ws: Worksheet, ie: IgnoredError): IgnoredErrorParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
ie | IgnoredError |
Returns
IgnoredError
# addTable function
src/worksheet/worksheet.ts:2027Append a table. The id and displayName must be workbook-unique — the caller is responsible.
function addTable(ws: Worksheet, table: TableDefinition): TableDefinitionParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
table | TableDefinition |
Returns
TableDefinition
# appendRow function
src/worksheet/worksheet.ts:353Append a row of values starting at the next empty row. Returns the row index (1-based). Mirrors openpyxl's `Worksheet.append`. `null` / `undefined` entries leave the cell empty.
function appendRow(ws: Worksheet, values: readonly (CellValue | undefined)[]): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
values | readonly (CellValue | undefined)[] |
Returns
number
# appendRows function
src/worksheet/worksheet.ts:374Bulk version of appendRow: append a 2D array of values one row at a time. Returns `{firstRow, lastRow}` — both 1-based, inclusive. An empty input returns `{firstRow, lastRow: firstRow - 1}` so callers can detect the no-op without throwing. Common usage: `appendRows(ws, csvParsedRows)` for fast import.
function appendRows(ws: Worksheet, rows: readonly readonly (CellValue | undefined)[][]): { firstRow: number; lastRow: number }Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
rows | readonly readonly (CellValue | undefined)[][] |
Returns
{ firstRow: number; lastRow: number }
# applyToRange function
src/worksheet/worksheet.ts:1210Iterate over every cell coordinate in a range, calling `visit` once per (row, col). Allocates the cell on first touch so callers can mutate it freely.
function applyToRange(ws: Worksheet, range: string, visit: (cell: Cell, row: number, col: number) => void): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
range | string | |
visit | (cell: Cell, row: number, col: number) => void |
Returns
void
# autofitColumns function
src/worksheet/worksheet.ts:1776Approximate autofit for every column with at least one populated cell. Walks the worksheet once collecting per-column widest-length + applies autofitColumn per column. `opts.workbook` enables font-size-aware scaling; without it the helper falls back to plain string length.
function autofitColumns(ws: Worksheet, opts?: { max?: number; min?: number; padding?: number; workbook?: { styles: { cellXfs: readonly { fontId: number }[]; fonts: readonly { size?: number }[] } } }): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
opts? = {} | { max?: number; min?: number; padding?: number; workbook?: { styles: { cellXfs: readonly { fontId: number }[]; fonts: readonly { size?: number }[] } } } |
Returns
void
# clearAllCells function
src/worksheet/worksheet.ts:340Wipe every populated cell on the worksheet, leaving styles, dimensions, merges, comments, hyperlinks etc. intact. Returns the count of cells removed. Useful when a sheet should be re-filled from scratch but its formatting kept.
function clearAllCells(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# clearRange function
src/worksheet/worksheet.ts:321Delete every populated cell inside a range. Returns the number of cells removed. Row maps that go empty are pruned. Column / row dimensions, merges, comments etc. are left untouched.
function clearRange(ws: Worksheet, range: string): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
range | string |
Returns
number
# collapseColumnGroup function
src/worksheet/worksheet.ts:1678Collapse a column outline group: hide + mark `collapsed: true` for every column in `[fromCol, toCol]`. Columns must already carry an `outlineLevel` from groupColumns for the collapse to render correctly.
function collapseColumnGroup(ws: Worksheet, fromCol: number, toCol: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromCol | number | |
toCol | number |
Returns
void
# collapseRowGroup function
src/worksheet/worksheet.ts:1646Collapse a row outline group: hide every row in `[fromRow, toRow]` and mark them `collapsed: true`. Mirrors Excel's `−` button on a grouped row strip. Rows must already carry an `outlineLevel` from groupRows for the collapse to render correctly.
function collapseRowGroup(ws: Worksheet, fromRow: number, toRow: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromRow | number | |
toRow | number |
Returns
void
# copyRange function
src/worksheet/worksheet.ts:1259Copy every populated cell from `source` to `target` (within the same worksheet, or across worksheets via `targetWs`). Cells are shallow-cloned: `value` and `styleId` carry over but `row`/`col` are rewritten. The target's existing cells in the destination extent are overwritten; cells outside are untouched. The source and target ranges define the top-left corner — their dimensions need not match. If the target range is smaller than the source, only the cells that fit within the target's extent are copied; if larger, only the source's extent is filled. Returns the number of cells copied.
function copyRange(ws: Worksheet, source: string, target: string, opts?: { targetWs?: Worksheet }): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
source | string | |
target | string | |
opts? = {} | { targetWs?: Worksheet } |
Returns
number
# countCells function
src/worksheet/worksheet.ts:666Total populated cell count.
function countCells(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# countCellsByKind function
src/worksheet/worksheet.ts:583function countCellsByKind(ws: Worksheet): CellsByKindCountsParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
CellsByKindCounts
# deleteCell function
src/worksheet/worksheet.ts:309Delete a single cell from the sheet. Empty rows are pruned.
function deleteCell(ws: Worksheet, row: number, col: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number | |
col | number |
Returns
void
# expandColumnGroup function
src/worksheet/worksheet.ts:1692Expand a column outline group: drop `hidden` and `collapsed` from every column in `[fromCol, toCol]`. Leaves `outlineLevel` intact.
function expandColumnGroup(ws: Worksheet, fromCol: number, toCol: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromCol | number | |
toCol | number |
Returns
void
# expandRowGroup function
src/worksheet/worksheet.ts:1660Expand a row outline group: drop the `hidden` and `collapsed` flags on every row in `[fromRow, toRow]`. Leaves `outlineLevel` and other dimensions intact.
function expandRowGroup(ws: Worksheet, fromRow: number, toRow: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromRow | number | |
toRow | number |
Returns
void
# findCells function
src/worksheet/worksheet.ts:720Iterate every populated cell, yielding those for which `predicate` returns true. Iteration order is row-then-column ascending. Cells whose `.value === null` (empty placeholders carrying only style or comment metadata) are still visited.
function findCells(ws: Worksheet, predicate: (c: Cell) => boolean): IterableIterator<Cell>Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
predicate | (c: Cell) => boolean |
Returns
IterableIterator<Cell>
# freezePanes function
src/worksheet/worksheet.ts:1044Freeze both top `rows` rows AND left `cols` columns.
function freezePanes(ws: Worksheet, rows: number, cols: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
rows | number | |
cols | number |
Returns
void
# getAutoFilter function
src/worksheet/worksheet.ts:2020Read the current AutoFilter, if any.
function getAutoFilter(ws: Worksheet): AutoFilter | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
AutoFilter | undefined
# getCell function
src/worksheet/worksheet.ts:280Resolve a 1-based or "A1" coordinate; returns the populated Cell or undefined.
function getCell(ws: Worksheet, row: number, col: number): Cell | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number | |
col | number |
Returns
Cell | undefined
# getCellByCoord function
src/worksheet/worksheet.ts:883Convenience getter accepting an "A1" coordinate.
function getCellByCoord(ws: Worksheet, coord: string): Cell | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
coord | string |
Returns
Cell | undefined
# getCellsInColumn function
src/worksheet/worksheet.ts:1439Enumerate the populated cells of a column in row order. Walks the row map and collects whichever rows carry the column. Returns `[]` when the worksheet has no cell in that column.
function getCellsInColumn(ws: Worksheet, col: number): Cell[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
col | number |
Returns
Cell[]
# getCellsInRange function
src/worksheet/worksheet.ts:805Iterate the populated cells inside a rectangular range. Cells that don't exist in the sparse store are skipped (no auto-allocate). Use applyToRange when you need every coordinate visited regardless of population.
function getCellsInRange(ws: Worksheet, range: string): IterableIterator<Cell>Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
range | string |
Returns
IterableIterator<Cell>
# getCellsInRow function
src/worksheet/worksheet.ts:1422Enumerate the populated cells of a row in column order. Unlike getRowValues, this skips empty columns and yields the cell objects (not just their values). Returns `[]` when the row is absent or empty.
function getCellsInRow(ws: Worksheet, row: number): Cell[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number |
Returns
Cell[]
# getColumnDimension function
src/worksheet/worksheet.ts:1456Look up the ColumnDimension covering `col`. The search walks every registered entry's `min..max` range; that's fine for the typical spreadsheet (a handful of column entries) and stays simple.
function getColumnDimension(ws: Worksheet, col: number): ColumnDimension | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
col | number |
Returns
ColumnDimension | undefined
# getDataExtent function
src/worksheet/worksheet.ts:677Bounding-box of the populated cells: `{ minRow, maxRow, minCol, maxCol }` covering every cell in `ws.rows`. Returns `undefined` when the sheet is empty. Walks the sparse store once.
function getDataExtent(ws: Worksheet): { maxCol: number; maxRow: number; minCol: number; minRow: number } | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
{ maxCol: number; maxRow: number; minCol: number; minRow: number } | undefined
# getFreezePanes function
src/worksheet/worksheet.ts:1014Inverse of setFreezePanes; returns the top-left ref or undefined when no freeze is active.
function getFreezePanes(ws: Worksheet): string | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
string | undefined
# getMaxCol function
src/worksheet/worksheet.ts:502Effective max column index based on populated cells (0 when empty).
function getMaxCol(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# getMaxRow function
src/worksheet/worksheet.ts:495Effective max row index based on populated cells (0 when empty).
function getMaxRow(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# getMergedCells function
src/worksheet/worksheet.ts:936Read-only iterator over the worksheet's merged ranges.
function getMergedCells(ws: Worksheet): readonly CellRangeBoundaries[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
readonly CellRangeBoundaries[]
# getMergedRangeAt function
src/worksheet/worksheet.ts:953Look up the merged range covering (row, col), or `undefined` if the coordinate isn't inside any merge. Lets callers introspect a merge without iterating `getMergedCells` themselves.
function getMergedRangeAt(ws: Worksheet, row: number, col: number): CellRangeBoundaries | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number | |
col | number |
Returns
CellRangeBoundaries | undefined
# getNonEmptyCellCount function
src/worksheet/worksheet.ts:645Count non-empty cells. Distinct from countCells which counts every materialised cell (including ones whose `value === null`): this skips cells with a `null` value, plus optionally formulas / rich-text per the opts. Useful for "how many real values does this sheet contain" stats vs the materialised footprint.
function getNonEmptyCellCount(ws: Worksheet, opts?: { includeFormulas?: boolean; includeRichText?: boolean }): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
opts? = {} | { includeFormulas?: boolean; includeRichText?: boolean } |
Returns
number
# getPopulatedColumnIndices function
src/worksheet/worksheet.ts:529Sorted list of every column index that holds at least one populated cell anywhere on the sheet. Distinct columns only; returns `[]` for an empty worksheet.
function getPopulatedColumnIndices(ws: Worksheet): number[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number[]
# getPopulatedRowIndices function
src/worksheet/worksheet.ts:516Sorted list of every row index that holds at least one populated cell. Returns `[]` for an empty worksheet. Useful when a caller wants to iterate only the rows the user actually populated, without walking 1..maxRow in dense fashion.
function getPopulatedRowIndices(ws: Worksheet): number[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number[]
# getRangeValues function
src/worksheet/worksheet.ts:1230Read a rectangular range as a dense 2-D array of values. Empty cells yield `null`. The shape is `[maxRow - minRow + 1] × [maxCol - minCol + 1]`. Inverse of setRangeValues.
function getRangeValues(ws: Worksheet, range: string): CellValue[][]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
range | string |
Returns
CellValue[][]
# getRowDimension function
src/worksheet/worksheet.ts:1831Look up a row's dimension entry.
function getRowDimension(ws: Worksheet, row: number): RowDimension | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number |
Returns
RowDimension | undefined
# getTable function
src/worksheet/worksheet.ts:2033Look up a table by displayName.
function getTable(ws: Worksheet, displayName: string): TableDefinition | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
displayName | string |
Returns
TableDefinition | undefined
# groupColumns function
src/worksheet/worksheet.ts:1606Mirror Excel's "Data → Group → Columns" by stamping every column in `[fromCol, toCol]` with an outline depth of `level` (default 1).
function groupColumns(ws: Worksheet, fromCol: number, toCol: number, level?: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromCol | number | |
toCol | number | |
level? = 1 | number |
Returns
void
# groupRows function
src/worksheet/worksheet.ts:1574Mirror Excel's "Data → Group → Rows" by stamping every row in `[fromRow, toRow]` with an outline depth of `level` (default 1). Allocates a RowDimension for each row that doesn't already have one. Ungroup with ungroupRows.
function groupRows(ws: Worksheet, fromRow: number, toRow: number, level?: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromRow | number | |
toRow | number | |
level? = 1 | number |
Returns
void
# hideColumn function
src/worksheet/worksheet.ts:1491Convenience: hide a column.
function hideColumn(ws: Worksheet, col: number): ColumnDimensionParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
col | number |
Returns
ColumnDimension
# hideColumns function
src/worksheet/worksheet.ts:1514Bulk-hide every column in `[fromCol, toCol]`.
function hideColumns(ws: Worksheet, fromCol: number, toCol: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromCol | number | |
toCol | number |
Returns
void
# hideRow function
src/worksheet/worksheet.ts:1875Convenience: hide a row.
function hideRow(ws: Worksheet, row: number): RowDimensionParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number |
Returns
RowDimension
# hideRows function
src/worksheet/worksheet.ts:1893Bulk-hide every row in `[fromRow, toRow]`.
function hideRows(ws: Worksheet, fromRow: number, toRow: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromRow | number | |
toRow | number |
Returns
void
# isWorksheetEmpty function
src/worksheet/worksheet.ts:630True iff the worksheet has zero non-empty cells. Equivalent to `getNonEmptyCellCount(ws) === 0` but short-circuits on the first non-null value found, so the cost is O(first non-empty cell) rather than O(populated cells).
function isWorksheetEmpty(ws: Worksheet): booleanParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
boolean
# iterCells function
src/worksheet/worksheet.ts:486Yield every populated cell in the worksheet as a flat stream (row-major, columns ascending). Distinct from iterRows which yields one row per row in the bounding box — use this when the caller wants only the populated cells without row boundaries or rectangular padding.
function iterCells(ws: Worksheet, opts?: IterRowsOptions): IterableIterator<Cell>Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
opts? = {} | IterRowsOptions |
Returns
IterableIterator<Cell>
# iterRows function
src/worksheet/worksheet.ts:450Iterate the worksheet rows rectangularly. Yields one row per row in `[minRow, maxRow]` — including entirely empty rows — and each yielded row has length `maxCol - minCol + 1`. Missing cell positions are `undefined` (no placeholder Cell allocations). Defaults: `minRow=1`, `maxRow=getMaxRow(ws)`, `minCol=1`, `maxCol=getMaxCol(ws)`. The default extent is the populated bounding box, not the 1M × 16K sheet limit, so the rectangular default doesn't iterate the whole grid for a small sheet. To iterate populated rows only, filter: `[...iterRows(ws)].filter(row => row.some((c) => c !== undefined))`. To iterate populated cells without row boundaries, use iterCells.
function iterRows(ws: Worksheet, opts?: IterRowsOptions): IterableIterator<(Cell | undefined)[]>Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
opts? = {} | IterRowsOptions |
Returns
IterableIterator<(Cell | undefined)[]>
# iterValues function
src/worksheet/worksheet.ts:474Same rectangular iteration as iterRows, but yields each cell's `.value`. Missing cell positions become `null` — already the canonical empty marker in `CellValue`.
function iterValues(ws: Worksheet, opts?: IterRowsOptions): IterableIterator<CellValue[]>Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
opts? = {} | IterRowsOptions |
Returns
IterableIterator<CellValue[]>
# listComments function
src/worksheet/worksheet.ts:2080Read-only snapshot of every legacy comment on the sheet.
function listComments(ws: Worksheet): readonly LegacyComment[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
readonly LegacyComment[]
# listDataValidations function
src/worksheet/worksheet.ts:1997Read-only snapshot of every data validation block on the sheet.
function listDataValidations(ws: Worksheet): readonly DataValidation[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
readonly DataValidation[]
# listHyperlinks function
src/worksheet/worksheet.ts:1950Read-only snapshot of every hyperlink on the sheet.
function listHyperlinks(ws: Worksheet): readonly Hyperlink[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
readonly Hyperlink[]
# listTables function
src/worksheet/worksheet.ts:2038Read-only snapshot of every Excel table defined on the sheet.
function listTables(ws: Worksheet): readonly TableDefinition[]Parameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
readonly TableDefinition[]
# makeWorksheet function
src/worksheet/worksheet.ts:239Build a Worksheet shell.
function makeWorksheet(title: string): WorksheetParameters
| Name | Type | Description |
|---|---|---|
title | string |
Returns
Worksheet
# mergeCells function
src/worksheet/worksheet.ts:903Merge a range. The top-left cell keeps its value; every other cell in the range is dropped from `ws.rows` so the on-wire `<sheetData>` won't carry phantom cells underneath the merge. Mirrors openpyxl's `MergedCellRange.format()`. Idempotent for an identical range, throws when the range overlaps an existing merge.
function mergeCells(ws: Worksheet, refOrRange: string | CellRangeBoundaries): CellRangeBoundariesParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
refOrRange | string | CellRangeBoundaries |
Returns
CellRangeBoundaries
# moveRange function
src/worksheet/worksheet.ts:1307Move every populated cell from `source` to `target`. Equivalent to `copyRange` followed by clearing the source. When the ranges overlap on the same sheet, the copy walks in the direction that preserves data — high-to-low along any axis where the move shifts forward, low-to-high otherwise — so cells aren't overwritten before they've been read. Returns the number of cells moved.
function moveRange(ws: Worksheet, source: string, target: string, opts?: { targetWs?: Worksheet }): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
source | string | |
target | string | |
opts? = {} | { targetWs?: Worksheet } |
Returns
number
# removeAllComments function
src/worksheet/worksheet.ts:2085Drop every legacy comment on the worksheet. Returns the count removed.
function removeAllComments(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# removeAllConditionalFormatting function
src/worksheet/worksheet.ts:2154Drop every conditional-formatting block on the worksheet. Returns the count removed.
function removeAllConditionalFormatting(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# removeAllDataValidations function
src/worksheet/worksheet.ts:2002Drop every data validation block on the worksheet. Returns the count removed.
function removeAllDataValidations(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# removeAllHyperlinks function
src/worksheet/worksheet.ts:1938Drop every hyperlink on the worksheet. Returns the count removed.
function removeAllHyperlinks(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# removeAllMergedRanges function
src/worksheet/worksheet.ts:981Drop every merged range on the worksheet. Returns the count of merges removed. Cells that were inside the merges keep their values — only the merge metadata is gone.
function removeAllMergedRanges(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# removeAllTables function
src/worksheet/worksheet.ts:2051Drop every Excel table on the worksheet. Returns the count removed.
function removeAllTables(ws: Worksheet): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet |
Returns
number
# removeCellWatches function
src/worksheet/worksheet.ts:2169Remove cell watches matching `predicate`. Returns the count removed.
function removeCellWatches(ws: Worksheet, predicate: (w: CellWatch) => boolean): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
predicate | (w: CellWatch) => boolean |
Returns
number
# removeDataValidations function
src/worksheet/worksheet.ts:1990Drop every validation whose sqref overlaps `ref` (string parse). Returns count removed.
function removeDataValidations(ws: Worksheet, predicate: (dv: DataValidation) => boolean): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
predicate | (dv: DataValidation) => boolean |
Returns
number
# removeHyperlink function
src/worksheet/worksheet.ts:1930Remove the hyperlink registered against `ref`. Returns true if anything was removed.
function removeHyperlink(ws: Worksheet, ref: string): booleanParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
ref | string |
Returns
boolean
# removeIgnoredErrors function
src/worksheet/worksheet.ts:2182Remove ignored-error entries matching `predicate`. Returns the count removed.
function removeIgnoredErrors(ws: Worksheet, predicate: (ie: IgnoredError) => boolean): numberParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
predicate | (ie: IgnoredError) => boolean |
Returns
number
# removeTable function
src/worksheet/worksheet.ts:2043Drop a table by displayName. Returns true when something was removed.
function removeTable(ws: Worksheet, displayName: string): booleanParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
displayName | string |
Returns
boolean
# setAutoFilter function
src/worksheet/worksheet.ts:2011Set or replace the worksheet's AutoFilter. Pass `undefined` to clear.
function setAutoFilter(ws: Worksheet, filter: AutoFilter | undefined): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
filter | AutoFilter | undefined |
Returns
void
# setCell function
src/worksheet/worksheet.ts:288Create or update a Cell at (row, col). Existing cells keep their styleId / hyperlinkId / commentId unless explicitly overridden.
function setCell(ws: Worksheet, row: number, col: number, value?: CellValue, styleId?: number): CellParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number | |
col | number | |
value? = null | CellValue | |
styleId? | number |
Returns
Cell
# setCellByCoord function
src/worksheet/worksheet.ts:872Resolve an "A1" coordinate to a numeric (col, row) pair on the sheet.
function setCellByCoord(ws: Worksheet, coord: string, value?: CellValue, styleId?: number): CellParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
coord | string | |
value? | CellValue | |
styleId? | number |
Returns
Cell
# setColumnDimension function
src/worksheet/worksheet.ts:1468Set a single-column ColumnDimension entry covering `col`. Shadows any existing run that overlaps — runs are not split for now (callers that need range-spanning entries can write directly into `ws.columnDimensions`).
function setColumnDimension(ws: Worksheet, col: number, opts: Partial<Omit<ColumnDimension, "min" | "max">>): ColumnDimensionParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
col | number | |
opts | Partial<Omit<ColumnDimension, "min" | "max">> |
Returns
ColumnDimension
# setColumnWidth function
src/worksheet/worksheet.ts:1485Convenience: set a column's width, leaving other fields untouched.
function setColumnWidth(ws: Worksheet, col: number, width: number): ColumnDimensionParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
col | number | |
width | number |
Returns
ColumnDimension
# setColumnWidths function
src/worksheet/worksheet.ts:1809Set widths for many columns in one call. `widths` maps either: - an array `[12, 16, 20]` interpreted positionally starting at column `startCol` (default 1), or - a `Record<number, number>` keyed by 1-based column index. Each entry sets `customWidth: true`.
function setColumnWidths(ws: Worksheet, widths: readonly number[] | Record<number, number>, startCol?: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
widths | readonly number[] | Record<number, number> | |
startCol? = 1 | number |
Returns
void
# setComment function
src/worksheet/worksheet.ts:2060Add or replace the comment at `ref`.
function setComment(ws: Worksheet, opts: { author: string; ref: string; text: string }): LegacyCommentParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
opts | { author: string; ref: string; text: string } |
Returns
LegacyComment
# setDefaultColumnWidth function
src/worksheet/worksheet.ts:1534Set the default column width (characters) for cells without an explicit ColumnDimension entry. Mirrors Excel's "Default Width" dialog. Pass `undefined` to clear.
function setDefaultColumnWidth(ws: Worksheet, width: number | undefined): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
width | number | undefined |
Returns
void
# setDefaultRowHeight function
src/worksheet/worksheet.ts:1550Set the default row height (points) for rows without an explicit RowDimension entry. Mirrors Excel's "Default Row Height" dialog. Pass `undefined` to clear.
function setDefaultRowHeight(ws: Worksheet, height: number | undefined): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
height | number | undefined |
Returns
void
# setFreezePanes function
src/worksheet/worksheet.ts:1004Freeze rows / columns above + left of `topLeftRef` ("B2" → 1 row + 1 col). Pass `undefined` to clear any existing freeze. Targets the workbook's primary SheetView (`ws.views[0]`); creates one if absent.
function setFreezePanes(ws: Worksheet, topLeftRef: string | undefined): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
topLeftRef | string | undefined |
Returns
void
# setHyperlink function
src/worksheet/worksheet.ts:1915Replace any prior hyperlink on the same `ref` with the given options. Pass `{ target }` for an external URL, `{ location }` for an internal jump, or both. Returns the resulting Hyperlink record.
function setHyperlink(ws: Worksheet, ref: string, opts: { display?: string; location?: string; target?: string; tooltip?: string }): HyperlinkParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
ref | string | |
opts | { display?: string; location?: string; target?: string; tooltip?: string } |
Returns
Hyperlink
# setRangeValues function
src/worksheet/worksheet.ts:1189Set values across a rectangular range from a 2-D array. `rows[0]` is laid down starting at the top-left of `range`; subsequent rows follow. `null` / `undefined` entries skip the cell. Useful for dropping a header + data block in one call.
function setRangeValues(ws: Worksheet, range: string, rows: readonly readonly (CellValue | undefined)[][]): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
range | string | |
rows | readonly readonly (CellValue | undefined)[][] |
Returns
void
# setRowDimension function
src/worksheet/worksheet.ts:1835function setRowDimension(ws: Worksheet, row: number, opts: Partial<RowDimension>): RowDimensionParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number | |
opts | Partial<RowDimension> |
Returns
RowDimension
# setRowHeight function
src/worksheet/worksheet.ts:1843Convenience: set a row's height, marking customHeight=true.
function setRowHeight(ws: Worksheet, row: number, height: number): RowDimensionParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number | |
height | number |
Returns
RowDimension
# setRowHeights function
src/worksheet/worksheet.ts:1853Set heights for many rows in one call. `heights` accepts an array (positional from `startRow`, default 1) or a `Record<number, number>` keyed by 1-based row index. Each entry sets `customHeight: true`.
function setRowHeights(ws: Worksheet, heights: readonly number[] | Record<number, number>, startRow?: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
heights | readonly number[] | Record<number, number> | |
startRow? = 1 | number |
Returns
void
# setSheetTabColor function
src/worksheet/worksheet.ts:1094Set the sheet tab strip colour. Accepts either a hex string (`"FF0070C0"`) or a partial `Color` object (`{ theme: 4, tint: 0.4 }`).
function setSheetTabColor(ws: Worksheet, color: string | Partial<Color>): ColorParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
color | string | Partial<Color> |
Returns
Color
# setSheetViewMode function
src/worksheet/worksheet.ts:1143Switch the sheet view between Excel's "Normal" / "Page Break Preview" / "Page Layout" modes.
function setSheetViewMode(ws: Worksheet, mode: "normal" | "pageBreakPreview" | "pageLayout"): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
mode | "normal" | "pageBreakPreview" | "pageLayout" |
Returns
void
# setSheetZoom function
src/worksheet/worksheet.ts:1135Set the zoom scale (percent) on the primary SheetView. Excel accepts integer percentages in `[10, 400]`.
function setSheetZoom(ws: Worksheet, scale: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
scale | number |
Returns
void
# ungroupColumns function
src/worksheet/worksheet.ts:1621Drop the outline grouping for every column in `[fromCol, toCol]`. Removes the `outlineLevel` field from each affected ColumnDimension.
function ungroupColumns(ws: Worksheet, fromCol: number, toCol: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromCol | number | |
toCol | number |
Returns
void
# ungroupRows function
src/worksheet/worksheet.ts:1589Drop the outline grouping for every row in `[fromRow, toRow]`. Removes the `outlineLevel` field from each affected RowDimension.
function ungroupRows(ws: Worksheet, fromRow: number, toRow: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromRow | number | |
toRow | number |
Returns
void
# unhideColumn function
src/worksheet/worksheet.ts:1501Convenience: unhide a column. Drops the `hidden` flag from the column's dimension entry (and removes the entry altogether when no other fields remain).
function unhideColumn(ws: Worksheet, col: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
col | number |
Returns
void
# unhideColumns function
src/worksheet/worksheet.ts:1522Bulk-unhide every column in `[fromCol, toCol]`.
function unhideColumns(ws: Worksheet, fromCol: number, toCol: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromCol | number | |
toCol | number |
Returns
void
# unhideRow function
src/worksheet/worksheet.ts:1884Convenience: unhide a row. Drops the `hidden` flag from the row's dimension entry (and removes the entry altogether when no other fields remain).
function unhideRow(ws: Worksheet, row: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number |
Returns
void
# unhideRows function
src/worksheet/worksheet.ts:1901Bulk-unhide every row in `[fromRow, toRow]`.
function unhideRows(ws: Worksheet, fromRow: number, toRow: number): voidParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
fromRow | number | |
toRow | number |
Returns
void
# unmergeCells function
src/worksheet/worksheet.ts:927Drop a previously-merged range. No-op if the range isn't registered.
function unmergeCells(ws: Worksheet, refOrRange: string | CellRangeBoundaries): booleanParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
refOrRange | string | CellRangeBoundaries |
Returns
boolean
# unmergeCellsAt function
src/worksheet/worksheet.ts:965Drop the merge that contains (row, col), if any. Returns `true` when a merge was unregistered. Useful when callers know a cell coordinate but not the original merge bounds.
function unmergeCellsAt(ws: Worksheet, row: number, col: number): booleanParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
row | number | |
col | number |
Returns
boolean
# writeRange function
src/worksheet/worksheet.ts:403Write a 2D array of values to the sheet starting at the given A1 anchor cell. Distinct from appendRows (which always writes past `_appendRowCursor`) — this lets you place a block at an arbitrary location, e.g. mid-sheet table updates. `null` / `undefined` entries leave the corresponding cell **untouched** (existing cell + style are preserved). Pre-existing cells inside the written rectangle are overwritten in place, so their `styleId` survives the write. Returns the bounding-box of the written area as 1-based inclusive coordinates. An empty rows array returns `undefined` rather than an invalid zero-area range.
function writeRange(ws: Worksheet, startRef: string, values: readonly readonly (CellValue | undefined)[][]): { maxCol: number; maxRow: number; minCol: number; minRow: number } | undefinedParameters
| Name | Type | Description |
|---|---|---|
ws | Worksheet | |
startRef | string | |
values | readonly readonly (CellValue | undefined)[][] |
Returns
{ maxCol: number; maxRow: number; minCol: number; minRow: number } | undefined
Page setup
src/worksheet/page-setup.ts# makePageBreak function
src/worksheet/page-setup.ts:111function makePageBreak(opts?: PageBreak): PageBreakParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | PageBreak |
Returns
PageBreak
# makePageMargins function
src/worksheet/page-setup.ts:82function makePageMargins(opts?: Partial<PageMargins>): PageMarginsParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | Partial<PageMargins> |
Returns
PageMargins
# makePageSetup function
src/worksheet/page-setup.ts:93function makePageSetup(opts?: PageSetup): PageSetupParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | PageSetup |
Returns
PageSetup
# makePrintOptions function
src/worksheet/page-setup.ts:91function makePrintOptions(opts?: PrintOptions): PrintOptionsParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | PrintOptions |
Returns
PrintOptions
# HEADER_FOOTER_CODES const
src/worksheet/page-setup.ts:196Excel's reserved header / footer code tokens. Drop these into the left / center / right text inputs of buildHeaderFooterText (or directly into a setHeader / setFooter string) to render dynamic values at print time.
const HEADER_FOOTER_CODES: Readonly<{ date: "&D"; fileName: "&F"; filePath: "&Z&F"; pageCount: "&N"; pageNumber: "&P"; picture: "&G"; sheetName: "&A"; time: "&T" }>Scenarios
src/worksheet/scenarios.ts# makeScenario function
src/worksheet/scenarios.ts:50function makeScenario(opts: Scenario): ScenarioParameters
| Name | Type | Description |
|---|---|---|
opts | Scenario |
Returns
Scenario
# makeScenarioInputCell function
src/worksheet/scenarios.ts:42function makeScenarioInputCell(opts: ScenarioInputCell): ScenarioInputCellParameters
| Name | Type | Description |
|---|---|---|
opts | ScenarioInputCell |
Returns
ScenarioInputCell
# makeScenarioList function
src/worksheet/scenarios.ts:59function makeScenarioList(opts?: Partial<ScenarioList>): ScenarioListParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | Partial<ScenarioList> |
Returns
ScenarioList
Smart tags
src/worksheet/smart-tags.tsViews
src/worksheet/views.ts# freezePaneRef function
src/worksheet/views.ts:100Inverse of makeFreezePane. Returns the top-left ref of the bottomRight pane, or undefined.
function freezePaneRef(view: SheetView): string | undefinedParameters
| Name | Type | Description |
|---|---|---|
view | SheetView |
Returns
string | undefined
# makeFreezePane function
src/worksheet/views.ts:78Build a frozen Pane from a top-left coordinate. Per Excel semantics: - "B2" → freeze 1 row + 1 col → xSplit=1, ySplit=1, activePane='bottomRight' - "A2" → freeze 1 row only → ySplit=1, activePane='bottomLeft' - "B1" → freeze 1 col only → xSplit=1, activePane='topRight' - "A1" → no freeze; throws (caller should clear `ws.views[].pane`).
function makeFreezePane(topLeftRef: string): PaneParameters
| Name | Type | Description |
|---|---|---|
topLeftRef | string |
Returns
Pane
# makeSheetView function
src/worksheet/views.ts:53Build a SheetView with sensible defaults.
function makeSheetView(opts?: Partial<SheetView>): SheetViewParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | Partial<SheetView> |
Returns
SheetView
Dimensions
src/worksheet/dimensions.ts# makeColumnDimension function
src/worksheet/dimensions.ts:50Build a single-column ColumnDimension entry covering `col`.
function makeColumnDimension(col: number, opts?: Partial<Omit<ColumnDimension, "min" | "max">>): ColumnDimensionParameters
| Name | Type | Description |
|---|---|---|
col | number | |
opts? = {} | Partial<Omit<ColumnDimension, "min" | "max">> |
Returns
ColumnDimension
# makeRowDimension function
src/worksheet/dimensions.ts:67function makeRowDimension(opts?: Partial<RowDimension>): RowDimensionParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | Partial<RowDimension> |
Returns
RowDimension
Errors
src/worksheet/errors.ts# makeCellWatch function
src/worksheet/errors.ts:52function makeCellWatch(ref: string): CellWatchParameters
| Name | Type | Description |
|---|---|---|
ref | string |
Returns
CellWatch
# makeIgnoredError function
src/worksheet/errors.ts:54function makeIgnoredError(opts: Partial<IgnoredError> & { sqref: MultiCellRange }): IgnoredErrorParameters
| Name | Type | Description |
|---|---|---|
opts | Partial<IgnoredError> & { sqref: MultiCellRange } |
Returns
IgnoredError
Ole objects
src/worksheet/ole-objects.ts# makeFormControl function
src/worksheet/ole-objects.ts:57function makeFormControl(opts: Partial<FormControl> & { shapeId: number }): FormControlParameters
| Name | Type | Description |
|---|---|---|
opts | Partial<FormControl> & { shapeId: number } |
Returns
FormControl
# makeOleObject function
src/worksheet/ole-objects.ts:46function makeOleObject(opts: Partial<OleObject> & { shapeId: number }): OleObjectParameters
| Name | Type | Description |
|---|---|---|
opts | Partial<OleObject> & { shapeId: number } |
Returns
OleObject
Sort state
src/worksheet/sort-state.ts# makeSortCondition function
src/worksheet/sort-state.ts:51function makeSortCondition(opts: SortCondition): SortConditionParameters
| Name | Type | Description |
|---|---|---|
opts | SortCondition |
Returns
SortCondition
# makeSortState function
src/worksheet/sort-state.ts:53function makeSortState(opts: Partial<SortState> & { ref: string }): SortStateParameters
| Name | Type | Description |
|---|---|---|
opts | Partial<SortState> & { ref: string } |
Returns
SortState
Web publish
src/worksheet/web-publish.ts# makeWebPublishItem function
src/worksheet/web-publish.ts:37function makeWebPublishItem(opts: WebPublishItem): WebPublishItemParameters
| Name | Type | Description |
|---|---|---|
opts | WebPublishItem |
Returns
WebPublishItem
# makeWorksheetCustomProperty function
src/worksheet/web-publish.ts:30function makeWorksheetCustomProperty(opts: WorksheetCustomProperty): WorksheetCustomPropertyParameters
| Name | Type | Description |
|---|---|---|
opts | WorksheetCustomProperty |
Returns
WorksheetCustomProperty
Custom sheet views
src/worksheet/custom-sheet-views.ts# makeCustomSheetView function
src/worksheet/custom-sheet-views.ts:52function makeCustomSheetView(opts: Partial<CustomSheetView> & { guid: string }): CustomSheetViewParameters
| Name | Type | Description |
|---|---|---|
opts | Partial<CustomSheetView> & { guid: string } |
Returns
CustomSheetView
Data consolidate
src/worksheet/data-consolidate.ts# makeDataConsolidate function
src/worksheet/data-consolidate.ts:47function makeDataConsolidate(opts?: DataConsolidate): DataConsolidateParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | DataConsolidate |
Returns
DataConsolidate
Phonetic
src/worksheet/phonetic.ts# makeWorksheetPhoneticProperties function
src/worksheet/phonetic.ts:21function makeWorksheetPhoneticProperties(opts?: WorksheetPhoneticProperties): WorksheetPhoneticPropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | WorksheetPhoneticProperties |
Returns
WorksheetPhoneticProperties
Properties
src/worksheet/properties.ts# makeSheetProperties function
src/worksheet/properties.ts:47function makeSheetProperties(opts?: SheetProperties): SheetPropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | SheetProperties |
Returns
SheetProperties
Protected ranges
src/worksheet/protected-ranges.ts# makeProtectedRange function
src/worksheet/protected-ranges.ts:26function makeProtectedRange(opts: Partial<ProtectedRange> & { name: string; sqref: MultiCellRange }): ProtectedRangeParameters
| Name | Type | Description |
|---|---|---|
opts | Partial<ProtectedRange> & { name: string; sqref: MultiCellRange } |
Returns
ProtectedRange
Protection
src/worksheet/protection.ts# makeSheetProtection function
src/worksheet/protection.ts:43function makeSheetProtection(opts?: SheetProtection): SheetProtectionParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | SheetProtection |
Returns
SheetProtection