SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Interface IWorkbook

    An IWorkbook represents a collection of sheets, along with shared resources.

    This interface provides methods for accessing its elements and event handling.

    Most interactions with a workbook or sheet are done through a workbook range.

    interface IWorkbook {
        isIWorkbook: true;
        options: IWorkbook.ConstructorOptions;
        addListeners(
            listeners: IWorkbook.IListeners,
            options?: IListener.Options,
        ): Remove;
        addSheet(options?: string | number | ISheetCollection.AddOptions): ISheet;
        beginCommit(options?: string | ITransaction.OperationOptions): ITransaction;
        close(): void;
        createFormula(
            expression: string,
            coords?: Partial<CellCoords>,
            options?: CreateFormulaOptions,
        ): IFormula;
        doBatch<R = any>(
            callback: (commit: ICommit) => R | Promise<R>,
            options?: string | ITransaction.OperationOptions,
        ): R | Promise<R>;
        evaluate(
            formula: string,
            options?:
                | number
                | EvaluateOptions & Partial<CellCoords> & CreateFormulaOptions,
        ): Promise<Scalar | IRange<Scalar>>;
        find(options: string | FindOptions): Iterator<ICell>;
        findValidSheetName(sheetName: string): string;
        getCalculation(): ICalculation;
        getCell(address?: ICell.Address): ICell;
        getCodeName(): string | null;
        getComments(): ICommentCollection;
        getExternalBooks(): IExternalBookCollection;
        getId(): string;
        getLocale(): string;
        getLocaleOverrides(): LocaleProfileOverrides | null;
        getModules(): IModuleCollection;
        getName(): string | null;
        getNames(): INamedCollection;
        getNextSheet(index: number): ISheet;
        getOrigin(): IWorkbookIO.Origin;
        getPeople(): IPersonCollection;
        getPinnedLocale(): string | null;
        getPivotTables(): IPivotTableCollection;
        getPreviousSheet(index: number): ISheet;
        getProtection(): IWorkbookProtection;
        getRange(
            address?: ICellRange.Address,
            options?: ICellRange.GetRangeOptions,
        ): ICellRange;
        getRanges(
            address: ICellRanges.Address,
            options?: ICellRange.GetRangeOptions,
        ): ICellRanges;
        getResources(): IResourceCollection;
        getRuntime(): IRuntime;
        getScripts(): IScript;
        getSelectedCell(): ICell;
        getSelectedRange(options?: ICellRange.GetRangeOptions): ICellRange;
        getSelectedRanges(options?: ICellRange.GetRangeOptions): ICellRanges;
        getSelectedSheet(): ISheet;
        getSelectedSheetIndex(): number;
        getSheet(name?: string, visibility?: ISheet.Visibility): ISheet;
        getSheetAt(index: number, visibility?: ISheet.Visibility): ISheet;
        getSheets(): ISheetCollection;
        getStats(options?: GetStatsOptions): IRangeStats;
        getStrings(): IStringCollection;
        getStyles(): IStyleCollection;
        getTheme(): ITheme;
        getTransactions(): IStore;
        getUpdateLinks(): UpdateLinks | null;
        getVersionId(): number;
        getView(): IWorkbookView;
        isClosed(): boolean;
        isValidSheetNameCharacter(character: string): boolean;
        replace(
            cells: Iterator<ICell>,
            replace: ICell.Update | ((original: ICell) => ICell.Update),
            options?: ReplaceOptions,
        ): ReplaceResults;
        setDate1904(date1940: boolean): this;
        setLocale(locale: string | null): this;
        setLocaleOverrides(overrides: LocaleProfileOverrides | null): this;
        setTheme(theme: ITheme | null): ITheme;
        setUpdateLinks(updateLinks: UpdateLinks | null): this;
        setView(view: IWorkbookView): this;
        toJSON(options?: ToJSONOptions): Promise<IWorkbook.JSON>;
        whenCalculationReady(): Promise<ICalculation.Status>;
    }

    Hierarchy (View Summary)

    Implemented by

    Index
    isIWorkbook: true

    For runtime type checking.

    Returns any custom workbook options that are provided in constructor.

    • Batches all 'transactional' changes until they have all be committed or rolled back.

      Parameters

      • Optionaloptions: string | ITransaction.OperationOptions

        Description of the operation or additional options. Used for tracking undo/redo and history. Default Value User Operation.

      Returns ITransaction

      Any changes that are made to this object will be reflected in the local record but not committed to the transactional store until the batch is popped.

      Useful for operations that are longer running but generally not recommended as it keeps a transaction open. doBatch is the preferred option.

    • Close the workbook and release any resources.

      Returns void

      No further operations are allowed after a close.

    • Parses a formula expression and returns a transient formula object.

      Parameters

      • expression: string

        The formula expression to parse.

      • Optionalcoords: Partial<CellCoords>

        Optional anchor coordinates.

      • Optionaloptions: CreateFormulaOptions

        Optional parse options; the expression is storage text unless target is 'display'.

      Returns IFormula

      This is a convenience method for getCalculation().createFormula(expression, coords, options). A bare reference (A2) resolves against the active cell's sheet; use ISheet.createFormula to anchor against a specific sheet.

    • Provides a mechanism to perform a set of operations in a batch.

      Type Parameters

      • R = any

      Parameters

      • callback: (commit: ICommit) => R | Promise<R>

        A callback that performs multiple operations all within the same transaction.

      • Optionaloptions: string | ITransaction.OperationOptions

        Description of the operation or additional options. Used for tracking undo/redo and history. Default Value User Operation.

      Returns R | Promise<R>

      Writes are tracked automatically: a batch that performs no state updates (a read-only batch) is elided — the commit id is unchanged, no events fire, and nothing is added to the undo stack or commit log.

    • Evaluates a formula in the context of the sheet and returns the resulting value.

      Parameters

      Returns Promise<Scalar | IRange<Scalar>>

      This is similar convenience method for getCalculation().createFormula(expression).evaluate(options).

    • Given the name return a valid name that closely matches.

      Parameters

      • sheetName: string

        The string to validate.

      Returns string

    • Returns a ICell at the specified address.

      Parameters

      • Optionaladdress: ICell.Address

        Address of the cell, optionally sheet-qualified (e.g. 'Sales!B11'). Omit for the selected cell — selection is modeled by the SDK (not a UI mode), and many operations default to it. getSelectedCell remains the explicit form.

      Returns ICell

      An address that resolves to more than a single cell is an error.

    • The workbook's VBA code name — conventionally ThisWorkbook — or null if it has none.

      Returns string | null

      null
      

      The workbook-level counterpart to ISheet.getCodeName: the identifier VBA binds the workbook's own document module through, where workbook event handlers such as Workbook_Open live. Like a sheet's, it is carried from the file and read-only — see ISheet.getCodeName for why SheetXL never mints one.

    • The workbook's external books — cached snapshots of other workbooks, addressed from a formula as [n]Sheet1!$A$1. In [n] order.

      Returns IExternalBookCollection

      A link is made by a formula — typing 'C:\path\[Budget.xlsx]Sheet1'!A1 adds a book here — and removed by breaking it (IExternalBookCollection.breakLink). Each book lists the formulas that cite it (IExternalBook.getDependents). The engine's collection, so available once the calculation is constructed, which is before any sheet is.

    • Returns the regional locale of the workbook as a BCP 47 tag, e.g. de-DE.

      Returns string

      Determines number/date formatting and parsing, separators, and collation. Falls back to the environment locale when the workbook does not pin one.

    • Returns the workbook's locale-profile overrides (the regional-override patch), or null when the profile is entirely Intl-derived from IWorkbook.getLocale.

      Returns LocaleProfileOverrides | null

    • Returns the modules this workbook owns.

      Returns IModuleCollection

      The workbook half of ISheet.getModules, and the same collection getScripts().getModules() answers with — modules belong to the model, whereas IScript is what runs them.

      Holds the globally scoped modules, whose functions ARE in the formula namespace, and the workbook-scoped ones, whose functions are not (IModule.getScope). A sheet's modules are not in here at all; they hang off the sheet.

      Like every module collection, this filters to TypeScript unless asked otherwise; imported VBA is read with getItems({ language: 'vba' }).

    • Returns the display name for the workbook — a pure, read-only derivation of its origin's name — or null for an unbound, unnamed workbook.

      Returns string | null

      A workbook has no intrinsic name (like Excel: a workbook's name is its file name). Display fallbacks (a localized "Untitled") are a UI concern. Renaming is an origin-level operation (see IWorkbookIO.Origin.setName), never a model edit — it is not undoable.

    • Every INamed in the workbook — global names, every sheet's scoped names, and every table — sorted by type then by name.

      Returns INamedCollection

      The name-manager view: what EXISTS, not what any one sheet can see. A global name and a sheet-scoped name that share a name are two items here and both are returned; ask ISheet.getNames for the one a formula on that sheet would resolve to.

    • Returns the next sheet in the sheets collection. If the last one it will return the first.

      Parameters

      • index: number

      Returns ISheet

      If there is only 1 sheet this will return the current sheet.

    • Returns the workbook's origin — the file handle it lives in.

      Returns IWorkbookIO.Origin

      Always present: a new in-memory workbook holds an unbound origin (getPath() null). Like the DOM's document.URL, which origin can change — a save that resolves a new destination (a first save, a Save As) moves the workbook to the file it wrote, firing onOriginChange. So read it when needed rather than holding it; to follow the current file, listen for onOriginChange.

      The model never mutates its origin, and the origin is not part of the persisted document (toJSON); a copy mints a fresh unbound origin.

    • Returns the locale explicitly pinned on the workbook, or null when it follows the environment locale.

      Returns string | null

      IWorkbook.getLocale always resolves to a concrete tag; this is the only way to tell a pinned locale from an environment fallback that happens to match it. Only a pinned locale is persisted.

    • Returns the previous sheet in the sheets collection. If the first one it will return the last.

      Parameters

      • index: number

      Returns ISheet

      If there is only 1 sheet this will return the current sheet.

    • Returns ranges scoped to a sheet.

      Parameters

      • Optionaladdress: ICellRange.Address

        Address of the ranges. Omit for the selected range — selection is modeled by the SDK (not a UI mode), and many operations default to it. getSelectedRange remains the explicit form.

      • Optionaloptions: ICellRange.GetRangeOptions

      Returns ICellRange

      When accessing ranges from the IWorkbook ranges include a sheet name. This enables cross-sheet references when working at the workbook level.

      Some examples of cross-sheet reference are:

      • Linking data and formulas across multiple sheets.

      • Consolidating data from different sheets for analysis or reporting.

      • Performing calculations or comparisons that involve values from multiple sheets.

    • Returns any user defined functions stored with the workbook.

      Returns IScript

    • Returns the selected cell.

      Returns ICell

    • Returns the currently active sheet within the workbook.

      Returns ISheet

    • Returns the currently active sheet index within the workbook.

      Returns number

    • Returns the sheet for the given name, or the selected sheet when no name is given.

      Parameters

      • Optionalname: string

        The name of the sheet. Omit for the selected sheet — "the sheet", unqualified, is the one the user (or agent) is looking at. getSelectedSheet remains the explicit form.

      • Optionalvisibility: ISheet.Visibility

        The visibility of the sheet.

      Returns ISheet

    • Returns the sheet at the given offset.

      Parameters

      • index: number

        A 0-based index of the sheet.

      • Optionalvisibility: ISheet.Visibility

        The visibility of the sheet.

      Returns ISheet

    • Returns the statistics for the used cells across all sheets.

      Parameters

      • Optionaloptions: GetStatsOptions

        Iterator options the stats are created with. At workbook scale prefer { onError: 'ignore' } — some error value existing somewhere is likely, and the default 'throw' policy treats one as a fault when aggregating.

      Returns IRangeStats

      The workbook form of ISheet.getStats: every sheet's used range contributes, including hidden and very-hidden sheets — visibility is a display concern, not a data one. A workbook with no used cells returns empty statistics (getSize() === 0), never null.

      Cross-sheet value ordering (where observable) follows sheet index order.

    • Returns the current shared resources.

      Returns IStore

    • When the cached values of getExternalBooks should be re-read from their sources on open, or null where the source file said nothing (which Excel reads as userSet).

      Returns UpdateLinks | null

      Carried, not obeyed — SheetXL never refreshes a link, so every mode behaves as never until a resolver exists. Round-trips as workbookPr@updateLinks.

      The mode is IExternalBookCollection.UpdateLinks: it governs the books as a set, and no single book has one. It is read and written HERE because it is a property of the workbook in both Excel's object model and the file, not of the collection the books live in.

    • Every committed update gives the record a new, strictly increasing version id.

      Returns number

      Used with getId to uniquely identify a version of the record.

      The id is an identity, not a per-record count: ids are drawn from a single store-wide sequence bumped once per commit, so all records written in the same commit share an id and a given record's ids increase but are not sequential.

      Records are immutable so a restore/revert doesn't change them — it repoints, and the version id reported is the one for the snapshot the store is currently at. Version ids are never reused: a write after an undo receives an id higher than any previously issued, so a stale reader can always detect the change.

    • Returns the current view settings.

      View settings determine how specific workbook level elements are displayed but does not affect the underlying data itself.

      Returns IWorkbookView

    • Indicates if the model has been closed.

      Returns boolean

    • Indicate if the current character is a valid character for a sheetName.

      Parameters

      • character: string

        The string to validate.

      Returns boolean

    • Determine if dates should be 1904 instead of 1900 based.

      Parameters

      • date1940: boolean

        default value false

      Returns this

      IWorkbook.isDate1904

    • Set the regional locale of the workbook.

      Parameters

      • locale: string | null

        A BCP 47 tag, e.g. de-DE. Pass null to follow the environment locale.

      Returns this

      This is a display/input concern only. Stored formulas, error values, and number formats remain canonical, so the workbook still opens correctly under any other locale.

    • Patch individual derived regional settings on top of the locale — the escape hatch for the OS-level customizations (a custom decimal symbol, a different currency) that browser Intl cannot see.

      Parameters

      • overrides: LocaleProfileOverrides | null

        A literal patch over the derived LocaleProfile (e.g. { decimal: '.', currencySymbol: 'CHF' }), or null to clear. Applied literally — nothing is re-derived, so patch listSeparator too if you patch decimal. Persisted in .sxl alongside the locale tag (never in .xlsx).

      Returns this

    • Set the current theme.

      Parameters

      Returns ITheme

      • If null sets back to the default theme.
      • Does not fire a theme updated event.
    • Views have their own lifecycle because in a collaborative environment each user can have their own view.

      Parameters

      Returns this

    • Returns when all calculations are complete and there are no pending calculations.

      Returns Promise<ICalculation.Status>

      • Also waits for the load-time start: the pass ICellContainerOptions.calcOnLoad asks for and the workbook's scripts. This is the settle point after constructing from JSON.
      • Otherwise a convenience method for getCalculation().ready(), which starts the engine if it has not been started.