Skip to content
Spreadsheet Engine

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, frozen panes).

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'],
});
new WorkbookView(workbook, index): WorkbookView;

Workbook

number

WorkbookView

get index(): number;

The zero-based index of this workbook view.

number

freezePanes(sheetName, panes): void;

Freezes panes for one particular sheet in this workbook view.

string

Name of the sheet whose panes should be frozen

Omit<WorksheetViewFrozenPanes, "type"> & object

Details of how the sheet view’s panes should be frozen

void

If a sheet with the given name doesn’t exist

If this view has been orphaned from its workbook

If the frozen panes are invalid (see validateFrozenPanes)


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


getFrozenPanes(sheetName): WorksheetViewFrozenPanes | null;

Return the frozen panes for a given sheet in this workbook view, if the sheet has them.

string

Name of the sheet whose frozen panes you want

WorksheetViewFrozenPanes | null

A copy of the JSF frozen panes, or null if the sheet has none

If a sheet with the given name doesn’t exist

If this view has been orphaned from its workbook


getSelection(sheetName): ViewSelection;

Returns the active cell and active ranges for a sheet.

Unlike getSheetView, activeCell is always present and 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 doesn’t include activeCell if it’s not set on the view explicitly.

string

WorksheetView | null

if sheetName does not exist


hasFrozenPanes(sheetName): boolean;

Returns true if the given sheet has frozen panes in this workbook view, false otherwise.

string

Name of the sheet you want to check for frozen panes

boolean

If a sheet with the given name doesn’t exist

If this view has been orphaned from its workbook


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


unfreezePanes(sheetName): void;

Unfreezes panes for one particular sheet in this workbook view.

If a sheet with the given name exists but doesn’t have frozen panes, this is a no-op.

string

Name of the sheet whose frozen panes should be removed

void

If a sheet with the given name doesn’t exist

If this view has been orphaned from its workbook