Workbook
Workbook root model: sheets, defined names, properties, calc settings.
Workbook
src/workbook/workbook.tsaddChartsheet function
src/workbook/workbook.ts:372Add 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:325Add 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:226Build 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:919function describeWorkbook(wb: Workbook): WorkbookOverviewParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
WorkbookOverview
getActiveSheet function
src/workbook/workbook.ts:1361Currently 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:842Resolve 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.
The address names the sheet, so there is no Worksheet argument. Use
getCellByCoord(ws, 'A1') from @office-kit/xlsx/worksheet when the
worksheet is already in hand.
function getCellAtAddress(wb: Workbook, address: string): Cell | undefinedParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
address | string |
Returns
Cell | undefined
getCellSummary function
src/workbook/workbook.ts:1034function 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:364Look 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:346Look 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
getSheetByIndex function
src/workbook/workbook.ts:358Look up a Worksheet by its 0-based tab-strip index. Returns undefined both
for an out-of-range index and for a slot holding a chartsheet, so one check
on the result covers the bounds test and the sheet-kind discrimination.
function getSheetByIndex(wb: Workbook, idx: number): Worksheet | undefinedParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
idx | number |
Returns
Worksheet | undefined
getSheetState function
src/workbook/workbook.ts:501Look 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:758Workbook-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:712function getWorkbookStats(wb: Workbook): WorkbookStatsParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
WorkbookStats
iterWorksheets function
src/workbook/workbook.ts:1080Iterate 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:1388Read-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:559Move 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:431Remove a sheet and its local defined names; reindex surviving scopes. No-op for an unknown title. Formula text is not rewritten.
function removeSheet(wb: Workbook, title: string): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
title | string |
Returns
void
renameSheet function
src/workbook/workbook.ts:454Rename 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). Formula text and defined-name
expressions are retained verbatim; callers must update sheet references.
PivotTable sources (ws.pivotTables[].source.sheet) do follow the rename.
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:441Set 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:856Set a single cell by sheet-qualified A1 address. Throws on malformed addresses, missing sheets, or range inputs.
The address names the sheet, so there is no Worksheet argument. Use
setCellByCoord(ws, 'A1', value) from @office-kit/xlsx/worksheet when the
worksheet is already in hand.
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:477Set 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:409Every sheet title in tab-strip order, chartsheets included, so a title in the list is not necessarily one getSheet resolves.
function sheetNames(wb: Workbook): string[]Parameters
| Name | Type | Description |
|---|---|---|
wb | Workbook |
Returns
string[]
Calc properties
src/workbook/calc-properties.tsmakeCalcProperties function
src/workbook/calc-properties.ts:34function makeCalcProperties(opts?: CalcProperties): CalcPropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | CalcProperties |
Returns
CalcProperties
setCalcMode function
src/workbook/calc-properties.ts:50Set the recalculation mode. 'auto' is Excel's default;
'manual' requires F9 to recompute formulas; 'autoNoTable'
recomputes everything except data-table cells.
function setCalcMode(wb: Workbook, mode: CalcMode): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
mode | CalcMode |
Returns
void
setCalcOnSave function
src/workbook/calc-properties.ts:71Toggle "Recalculate workbook before saving" (workbook-level).
function setCalcOnSave(wb: Workbook, on: boolean): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
on | boolean |
Returns
void
setFullCalcOnLoad function
src/workbook/calc-properties.ts:83Toggle "Recalculate workbook on load". A calculating app (Excel, LibreOffice, Google Sheets) then recomputes every formula on open instead of trusting the cached values in the file, which is what a generated workbook wants when the producer could not compute a cached value for every formula, or is not certain the ones it wrote are current. Viewers that never calculate ignore the flag and keep showing only what is cached.
function setFullCalcOnLoad(wb: Workbook, on: boolean): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
on | boolean |
Returns
void
setFullPrecision function
src/workbook/calc-properties.ts:88Toggle "Set precision as displayed" (false = full 15-digit precision).
function setFullPrecision(wb: Workbook, on: boolean): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
on | boolean |
Returns
void
setIterativeCalc function
src/workbook/calc-properties.ts:59Toggle iterative calculation (Excel's "Enable iterative calculation"
option). When enable is true and count / delta are provided,
they replace the default Excel limits (100 iterations, 0.001 delta).
function setIterativeCalc(wb: Workbook, enable: boolean, opts?: { count?: number; delta?: number }): voidParameters
| Name | Type | Description |
|---|---|---|
wb | Workbook | |
enable | boolean | |
opts? = {} | { count?: number; delta?: number } |
Returns
void
Defined names
src/workbook/defined-names.tsaddDefinedName function
src/workbook/defined-names.ts:63Add 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:121Look 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:141Resolve 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.
A leg with no sheet prefix on a sheet-scoped name resolves to the sheet the
scope points at. Files written by other tools, and by earlier versions of
setPrintArea, store _xlnm.Print_Area that way.
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:213Every defined name. Pass { scope } to narrow to workbook-scope
(scope: 'workbook') or one specific sheet (scope: 0); omit the option, or
pass 'all', to list every name. 'workbook' is the only spelling that
narrows to the unscoped ones: the option is number | 'workbook' | 'all', so
there is no undefined to pass for them.
A narrowed call filters, so it hands back a fresh array. Listing all hands
back a read-only view of the live one, which addDefinedName and
renameDefinedName are visible through and which removeDefinedNames
replaces outright.
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:27function 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:194Remove 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.tsmakeFunctionGroup 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.tsmakeCustomWorkbookView function
src/workbook/views.ts:73function 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:38function makeWorkbookView(opts?: WorkbookView): WorkbookViewParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | WorkbookView |
Returns
WorkbookView
File recovery
src/workbook/file-recovery.tsmakeFileRecoveryProperties function
src/workbook/file-recovery.ts:18function makeFileRecoveryProperties(opts?: FileRecoveryProperties): FileRecoveryPropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | FileRecoveryProperties |
Returns
FileRecoveryProperties
File sharing
src/workbook/file-sharing.tsmakeFileSharing function
src/workbook/file-sharing.ts:21function makeFileSharing(opts?: FileSharing): FileSharingParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | FileSharing |
Returns
FileSharing
File version
src/workbook/file-version.tsmakeFileVersion function
src/workbook/file-version.ts:20function makeFileVersion(opts?: FileVersion): FileVersionParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | FileVersion |
Returns
FileVersion
Persons
src/workbook/persons.tsmakePerson function
src/workbook/persons.ts:20Build a person with a new id. Without an account Excel records the display
name as the user id under provider None, so that is the default here too.
function makePerson(opts: { displayName: string; providerId?: string; userId?: string }): PersonParameters
| Name | Type | Description |
|---|---|---|
opts | { displayName: string; providerId?: string; userId?: string } |
Returns
Person
Protection
src/workbook/protection.tsmakeWorkbookProtection function
src/workbook/protection.ts:37function makeWorkbookProtection(opts?: WorkbookProtection): WorkbookProtectionParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | WorkbookProtection |
Returns
WorkbookProtection
Workbook properties
src/workbook/workbook-properties.tsmakeWorkbookProperties function
src/workbook/workbook-properties.ts:44function makeWorkbookProperties(opts?: WorkbookProperties): WorkbookPropertiesParameters
| Name | Type | Description |
|---|---|---|
opts? = {} | WorkbookProperties |
Returns
WorkbookProperties