WorkbookView
A single workbook view, bound to its index in workbook.views. Provides
access to the active sheet and per-sheet view state (selection, layout,
zoom).
Obtain via workbook.views.get(index) / .require(index); do not
construct directly.
All methods throw if the view has been removed from the workbook.
Example
Section titled “Example”const view = workbook.views.require();view.setActiveSheetName('Inputs');view.setSelection('Inputs', { activeCell: 'B5', activeRanges: ['B5:D10', 'F1'],});Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get index(): number;The zero-based index of this workbook view.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”getActiveSheetIndex()
Section titled “getActiveSheetIndex()”getActiveSheetIndex(): number;Index of the active sheet. Returns 0 when not explicitly set (OOXML default).
Returns
Section titled “Returns”number
getActiveSheetName()
Section titled “getActiveSheetName()”getActiveSheetName(): string | null;Name of the active sheet, or null if the stored index does not resolve to a sheet. Returns the first sheet when not explicitly set (OOXML default).
Note: deleting a sheet does not update the stored activeSheet index, so this may return null or the wrong sheet after a deletion.
Returns
Section titled “Returns”string | null
getSelection()
Section titled “getSelection()”getSelection(sheetName): ViewSelection;Returns the active cell and active ranges for a sheet. Hydrates defaults: activeCell is always present (defaults to ‘A1’).
Parameters
Section titled “Parameters”sheetName
Section titled “sheetName”string
Returns
Section titled “Returns”Throws
Section titled “Throws”if sheetName does not exist
getSheetView()
Section titled “getSheetView()”getSheetView(sheetName): WorksheetView | null;Returns the raw stored sheet view, or null if no view entry exists.
Unlike getSelection, this does not hydrate defaults --- absent fields
stay absent.
Parameters
Section titled “Parameters”sheetName
Section titled “sheetName”string
Returns
Section titled “Returns”WorksheetView | null
Throws
Section titled “Throws”if sheetName does not exist
setActiveSheetName()
Section titled “setActiveSheetName()”setActiveSheetName(sheetName): void;Set the active sheet by name.
Parameters
Section titled “Parameters”sheetName
Section titled “sheetName”string
Returns
Section titled “Returns”void
Throws
Section titled “Throws”if sheetName is empty or does not exist
setSelection()
Section titled “setSelection()”setSelection(sheetName, options?): void;Sets the active cell and active ranges for a sheet. This replaces the
full selection state --- any field you omit is cleared, not preserved.
Passing activeCell: 'A1' (or omitting it) with no activeRanges
resets the selection to default.
Parameters
Section titled “Parameters”sheetName
Section titled “sheetName”string
options?
Section titled “options?”activeCell?
Section titled “activeCell?”string
activeRanges?
Section titled “activeRanges?”string[]
Returns
Section titled “Returns”void
Throws
Section titled “Throws”if the sheet is not found
Throws
Section titled “Throws”if activeCell is not a valid cell reference
Throws
Section titled “Throws”if activeRanges contains an invalid range reference
Throws
Section titled “Throws”if activeCell is not contained within any of activeRanges