Skip to main content

Cell.Workbook

Cell.Workbook is an object type of the Spreadsheet module (Office.cell(iframe)). 13 methods.

Remarks​

  • Module: Spreadsheet · Office.cell(iframe) · namespace Cell
  • Obtained from: app.getDocument() / app.getWorkbook() (root handle) on the app handle returned by Office.cell(iframe). Document methods live on this handle, not on the app handle.
  • Navigation methods (getDefinedName(), getObjectById(), getTable()) return a child handle synchronously without a round trip; the request is sent by the next terminal call. Every other method returns a Promise.

Methods​

MethodDescription
addDefinedName(name, formula, sheet)Creates a defined name.
addSheet(name)Adds a new sheet at the end of the sheet list and makes it the active sheet.
copySheet(sheet)Copies a sheet and inserts the copy right after the original, and makes the copy the active sheet.
getDefinedName(name, sheet)Returns the defined name with the given name.
getDefinedNameList(sheet)Returns the list of defined names.
getDocumentProperties()Returns the document properties.
getObjectById(oid)Returns an object by ID.
getSheetList()Returns the sheets of the workbook as an array.
getTable(name)Returns a Table by name.
getWorksheet(sheet)Returns the Worksheet.
moveSheet(from, to)Moves the position of a sheet.
removeSheet(sheet)Deletes a sheet.
setActiveSheet(sheet)Changes the active sheet.

Method details​

addDefinedName(name, formula, sheet)​

Creates a defined name. References in the formula that do not specify a sheet are resolved against the active sheet. If sheet is omitted, the name is created as a workbook-scoped name. Throws an error if a defined name or table with the same name already exists.

addDefinedName(name: string, formula: string, sheet?: number | string): Promise<Name>;

Parameters

NameTypeDescription
namestringname to create
formulastringformula or reference that the name points to
sheet (optional)number | stringsheet that the name is scoped to. If omitted, the entire workbook

Returns

Promise<Name>

addSheet(name)​

Adds a new sheet at the end of the sheet list and makes it the active sheet.

addSheet(name: string): Promise<SheetRef>;

Parameters

NameTypeDescription
namestringnew sheet name

Returns

Promise<SheetRef>

copySheet(sheet)​

Copies a sheet and inserts the copy right after the original, and makes the copy the active sheet.

copySheet(sheet: number | string): Promise<SheetRef>;

Parameters

NameTypeDescription
sheetnumber | stringsheet to copy

Returns

Promise<SheetRef>

getDefinedName(name, sheet)​

Returns the defined name with the given name. The name is case-insensitive. If sheet is omitted, only workbook-scoped names are searched.

getDefinedName(name: string, sheet?: number | string): Name;

Parameters

NameTypeDescription
namestringname to look up
sheet (optional)number | stringsheet that the name is scoped to. If omitted, the entire workbook

Returns

Name

getDefinedNameList(sheet)​

Returns the list of defined names. Built-in names and names without a formula are excluded. If sheet is omitted, the workbook-scoped names are returned.

getDefinedNameList(sheet?: number | string): Promise<NameInfo[]>;

Parameters

NameTypeDescription
sheet (optional)number | stringsheet that the name is scoped to. If omitted, the entire workbook

Returns

Promise<NameInfo[]> - Formulas start with =

getDocumentProperties()​

Returns the document properties.

getDocumentProperties(): Promise<DocumentProperties>;

Returns

Promise<DocumentProperties>

getObjectById(oid)​

Returns an object by ID. It searches all sheets of the document, and currently only Chart is supported. Returns null for an object that is not a chart.

getObjectById(oid: string): Chart;

Parameters

NameTypeDescription
oidstringunique ID that identifies the object

Returns

Chart

getSheetList()​

Returns the sheets of the workbook as an array. The array index is the sheet index (0-based), and hidden sheets are included. Detailed properties of each sheet are read from Worksheet.

getSheetList(): Promise<SheetSummary[]>;

Returns

Promise<SheetSummary[]>

getTable(name)​

Returns a Table by name. The name is case-insensitive, and the returned Table holds the table name as actually stored.

getTable(name: string): Table;

Parameters

NameTypeDescription
namestringtable name. It is unique across the document

Returns

Table

getWorksheet(sheet)​

Returns the Worksheet. Sheet names are case-sensitive when the sheet is specified by name. If sheet is omitted, the active sheet is used.

getWorksheet(sheet?: number | string): Promise<Worksheet>;

Parameters

NameTypeDescription
sheet (optional)number | stringsheet index (0-based, the array index in the getSheetList() result) or sheet name

Returns

Promise<Worksheet>

moveSheet(from, to)​

Moves the position of a sheet.

moveSheet(from: number | string, to: number): Promise<void>;

Parameters

NameTypeDescription
fromnumber | stringsheet to move
tonumbersheet index (0-based) of the destination

Returns

none

removeSheet(sheet)​

Deletes a sheet. If the active sheet is deleted, an adjacent sheet becomes the active sheet. The sheet cannot be deleted if it is the only remaining sheet or the only visible sheet.

removeSheet(sheet: number | string): Promise<void>;

Parameters

NameTypeDescription
sheetnumber | stringsheet to delete

Returns

none

setActiveSheet(sheet)​

Changes the active sheet. A hidden sheet cannot be activated.

setActiveSheet(sheet: number | string): Promise<void>;

Parameters

NameTypeDescription
sheetnumber | stringsheet to activate

Returns

none