API reference
Workbook
Workbook root model: sheets, defined names, properties, calc settings.
Workbook
src/workbook/workbook.ts# addChartsheet function
src/workbook/workbook.ts:411Add a Chartsheet to the Workbook. Returns the chartsheet for further population.
function addChartsheet(wb: Workbook, title: string, opts?: { chart?: ChartReference; index?: number; state?: SheetState }): ChartsheetParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string | |
opts? | { chart?: ChartReference; index?: number; state?: SheetState } |
Returns
Chartsheet
# addWorksheet function
src/workbook/workbook.ts:287Add a Worksheet to the Workbook. Returns the sheet for further population.
function addWorksheet(wb: Workbook, title: string, opts?: { index?: number; state?: SheetState }): WorksheetParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string | |
opts? | { index?: number; state?: SheetState } |
Returns
Worksheet
# createWorkbook function
src/workbook/workbook.ts:189Build an empty Workbook ready to host worksheets.
function createWorkbook(opts?: { date1904?: boolean }): WorkbookParameters
| Name | Type | Description |
|---|---|---|
opts? | { date1904?: boolean } |
Returns
Workbook
# describeWorkbook function
src/workbook/workbook.ts:884function describeWorkbook(wb: Workbook): WorkbookOverviewParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
WorkbookOverview
# getActiveSheet function
src/workbook/workbook.ts:1326Currently active sheet (worksheet only), or undefined if the active slot is empty or a chartsheet.
function getActiveSheet(wb: Workbook): Worksheet | undefinedParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
Worksheet | undefined
# getCellAtAddress function
src/workbook/workbook.ts:793Resolve a sheet-qualified A1 address (`'Sheet1!A1'`) to its Cell, or `undefined` when the cell isn't materialised. Throws on malformed addresses, missing sheets, or range inputs.
function getCellAtAddress(wb: Workbook, address: string): Cell | undefinedParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
address | string |
Returns
Cell | undefined
# getCellSummary function
src/workbook/workbook.ts:999function getCellSummary(wb: Workbook, sheetTitle: string, ref: string): CellSummaryParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
sheetTitle | string | |
ref | string |
Returns
CellSummary
# getChartsheet function
src/workbook/workbook.ts:403Look up a Chartsheet by title. Returns undefined for missing names or worksheets.
function getChartsheet(wb: Workbook, title: string): Chartsheet | undefinedParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string |
Returns
Chartsheet | undefined
# getSheet function
src/workbook/workbook.ts:389Look up a Worksheet by title. Returns undefined for missing names or chartsheets.
function getSheet(wb: Workbook, title: string): Worksheet | undefinedParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string |
Returns
Worksheet | undefined
# getSheetState function
src/workbook/workbook.ts:514Look up the current visibility state. Throws on unknown title.
function getSheetState(wb: Workbook, title: string): SheetStateParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string |
Returns
SheetState
# getWorkbookCellsByKind function
src/workbook/workbook.ts:761Workbook-wide value-kind histogram. Sums countCellsByKind across every Worksheet (chartsheets contribute no cells). Buckets have the same shape as the per-worksheet result; an empty workbook returns all-zero counts.
function getWorkbookCellsByKind(wb: Workbook): CellsByKindCountsParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
CellsByKindCounts
# getWorkbookStats function
src/workbook/workbook.ts:715function getWorkbookStats(wb: Workbook): WorkbookStatsParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
WorkbookStats
# iterWorksheets function
src/workbook/workbook.ts:1045Iterate over every Worksheet in the workbook (skips chartsheets). Yields each worksheet in tab-strip order.
function iterWorksheets(wb: Workbook): IterableIterator<Worksheet>Parameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
IterableIterator<Worksheet>
# listCustomXmlParts function
src/workbook/workbook.ts:1353Read-only view onto the customXml/* pass-through parts.
function listCustomXmlParts(wb: Workbook): { content: Uint8Array; path: string }[]Parameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
{ content: Uint8Array; path: string }[]
# moveSheet function
src/workbook/workbook.ts:572Move a sheet to a new tab-strip position. `toIndex` is clamped to `[0, sheets.length - 1]`. Adjusts `activeSheetIndex` so the same sheet stays active across the move.
function moveSheet(wb: Workbook, title: string, toIndex: number): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string | |
toIndex | number |
Returns
void
# removeSheet function
src/workbook/workbook.ts:450Remove a sheet by title. No-op if the title is not registered.
function removeSheet(wb: Workbook, title: string): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string |
Returns
void
# renameSheet function
src/workbook/workbook.ts:472Rename a sheet from `oldTitle` to `newTitle`. Throws if no sheet matches `oldTitle`, or if `newTitle` collides with an existing sheet (Excel requires sheet names to be unique within a workbook).
function renameSheet(wb: Workbook, oldTitle: string, newTitle: string): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
oldTitle | string | |
newTitle | string |
Returns
void
# setActiveSheet function
src/workbook/workbook.ts:461Set the active sheet by title; throws on unknown title.
function setActiveSheet(wb: Workbook, title: string): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string |
Returns
void
# setCellAtAddress function
src/workbook/workbook.ts:812Set a single cell by sheet-qualified A1 address. Throws on malformed addresses, missing sheets, or range inputs.
function setCellAtAddress(wb: Workbook, address: string, value: CellValue): CellParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
address | string | |
value | CellValue |
Returns
Cell
# setSheetState function
src/workbook/workbook.ts:490Set the visibility state on a sheet by title. Throws on unknown title. Refuses to hide the last visible sheet: an .xlsx with every sheet hidden fails to open in Excel ("Excel cannot use the object linking and embedding features because no sheet is visible"). Catching it here keeps the workbook recoverable instead of producing a save Excel will reject.
function setSheetState(wb: Workbook, title: string, state: SheetState): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string | |
state | SheetState |
Returns
void
# sheetNames function
src/workbook/workbook.ts:445All worksheet titles, in display order.
function sheetNames(wb: Workbook): string[]Parameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
string[]
Defined names
src/workbook/defined-names.ts# addDefinedName function
src/workbook/defined-names.ts:59Add a workbook-scope or sheet-scope defined name. If a defined name with the same `name` (and `scope`) already exists, it's replaced — Excel allows one workbook-scope and one per-sheet-scope name, but not two with the same scope. Returns the resulting `DefinedName`.
function addDefinedName(wb: Workbook, opts: Partial<DefinedName> & { name: string; value: string }): DefinedNameParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
opts | Partial<DefinedName> & { name: string; value: string } |
Returns
DefinedName
# getDefinedName function
src/workbook/defined-names.ts:115Look up a defined name by identifier and (optional) sheet scope.
function getDefinedName(wb: Workbook, name: string, scope?: number): DefinedName | undefinedParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
name | string | |
scope? | number |
Returns
DefinedName | undefined
# getDefinedNameTarget function
src/workbook/defined-names.ts:131Resolve a defined name's `value` into one or more DefinedNameTargets. Comma-separated values (e.g. `_xlnm.Print_Titles` typically sets `Sheet!$1:$1,Sheet!$A:$A`) yield one entry per leg; a plain `Sheet!A1:B5` yields a single-element array. Returns `undefined` when the name doesn't exist; throws when the value can't be parsed (e.g. a constant or a non-range formula — defined names are sometimes used for things like `=42` or `=SUM(A:A)` which aren't ranges).
function getDefinedNameTarget(wb: Workbook, name: string, scope?: number): DefinedNameTarget[] | undefinedParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
name | string | |
scope? | number |
Returns
DefinedNameTarget[] | undefined
# listDefinedNames function
src/workbook/defined-names.ts:185Read-only snapshot of every defined name. Pass `{ scope }` to narrow to workbook-scope (`scope: undefined`) or one specific sheet (`scope: 0`) — omit the option entirely to list all.
function listDefinedNames(wb: Workbook, opts?: { scope?: number | "all" | "workbook" }): readonly DefinedName[]Parameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
opts? = {} | { scope?: number | "all" | "workbook" } |
Returns
readonly DefinedName[]
# makeDefinedName function
src/workbook/defined-names.ts:25function makeDefinedName(opts: Partial<DefinedName> & { name: string; value: string }): DefinedNameParameters
| Name | Type | Description |
|---|---|---|
opts | Partial<DefinedName> & { name: string; value: string } |
Returns
DefinedName
# removeDefinedName function
src/workbook/defined-names.ts:173Remove a defined name by identifier + scope. Returns true if any entry was removed.
function removeDefinedName(wb: Workbook, name: string, scope?: number): booleanParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
name | string | |
scope? | number |
Returns
boolean
Function groups
src/workbook/function-groups.ts# makeFunctionGroup function
src/workbook/function-groups.ts:18function makeFunctionGroup(name: string): FunctionGroupParameters
| Name | Type | Description |
|---|---|---|
name | string |
Returns
FunctionGroup
# makeFunctionGroups function
src/workbook/function-groups.ts:20function makeFunctionGroups(opts?: Partial<FunctionGroups>): FunctionGroupsParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | Partial<FunctionGroups> |
Returns
FunctionGroups
Smart tags
src/workbook/smart-tags.tsViews
src/workbook/views.ts# makeCustomWorkbookView function
src/workbook/views.ts:66function makeCustomWorkbookView(opts: Pick<CustomWorkbookView, "guid" | "name" | "windowWidth" | "windowHeight" | "activeSheetId"> & Partial<CustomWorkbookView>): CustomWorkbookViewParameters
| Name | Type | Description |
|---|---|---|
opts | Pick<CustomWorkbookView, "guid" | "name" | "windowWidth" | "windowHeight" | "activeSheetId"> & Partial<CustomWorkbookView> |
Returns
CustomWorkbookView
# makeWorkbookView function
src/workbook/views.ts:31function makeWorkbookView(opts?: WorkbookView): WorkbookViewParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | WorkbookView |
Returns
WorkbookView
Calc properties
src/workbook/calc-properties.ts# makeCalcProperties function
src/workbook/calc-properties.ts:34function makeCalcProperties(opts?: CalcProperties): CalcPropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | CalcProperties |
Returns
CalcProperties
File recovery
src/workbook/file-recovery.ts# makeFileRecoveryProperties function
src/workbook/file-recovery.ts:18function makeFileRecoveryProperties(opts?: FileRecoveryProperties): FileRecoveryPropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | FileRecoveryProperties |
Returns
FileRecoveryProperties
File sharing
src/workbook/file-sharing.ts# makeFileSharing function
src/workbook/file-sharing.ts:21function makeFileSharing(opts?: FileSharing): FileSharingParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | FileSharing |
Returns
FileSharing
File version
src/workbook/file-version.ts# makeFileVersion function
src/workbook/file-version.ts:20function makeFileVersion(opts?: FileVersion): FileVersionParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | FileVersion |
Returns
FileVersion
Protection
src/workbook/protection.ts# makeWorkbookProtection function
src/workbook/protection.ts:37function makeWorkbookProtection(opts?: WorkbookProtection): WorkbookProtectionParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | WorkbookProtection |
Returns
WorkbookProtection
Workbook properties
src/workbook/workbook-properties.ts# makeWorkbookProperties function
src/workbook/workbook-properties.ts:44function makeWorkbookProperties(opts?: WorkbookProperties): WorkbookPropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | WorkbookProperties |
Returns
WorkbookProperties