Skip to content

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.

const view = workbook.views.require();
view.setActiveSheetName('Inputs');
view.setSelection('Inputs', {
activeCell: 'B5',
activeRanges: ['B5:D10', 'F1'],
});
get index(): number;

The zero-based index of this workbook view.

number

getActiveSheetIndex(): number;

Index of the active sheet. Returns 0 when not explicitly set (OOXML default).

number


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.

string | null


getSelection(sheetName): ViewSelection;

Returns the active cell and active ranges for a sheet. Hydrates defaults: activeCell is always present (defaults to ‘A1’).

string

ViewSelection

if sheetName does not exist


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.

string

WorksheetView | null

if sheetName does not exist


setActiveSheetName(sheetName): void;

Set the active sheet by name.

string

void

if sheetName is empty or does not exist


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.

string

string

string[]

void

if the sheet is not found

if activeCell is not a valid cell reference

if activeRanges contains an invalid range reference

if activeCell is not contained within any of activeRanges