Skip to main content

Cell.Workbook

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

Generated from the SDK type definitions

Spreadsheet · 6 object types · 156 methods · namespace Cell. This reference is generated from the API document artifact (sdk-api-doc.html) produced with the SDK build. Descriptions are the editor's API comments as published. Pin the SDK and Office versions together and regenerate when either changes.

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, places 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 handle by ID.
getSheetList()Returns the document's sheet layout as an array.
getTable(name)Returns a table handle by name.
getWorksheet(sheet)Returns a sheet handle.
moveSheet(from, to)Moves a sheet's position.
removeSheet(sheet)Deletes a sheet.
setActiveSheet(sheet)Changes the active sheet.

Method details

addDefinedName(name, formula, sheet)

Creates a defined name. formula may start with = or not. A reference in the formula that does not name a sheet is resolved against the active sheet. Omitting sheet creates a name used across the whole document. It fails with an error when a defined name or a 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 the name points to
sheet (optional)number | stringthe sheet, when the name is used only on that sheet

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
namestringname of the new sheet

Returns

Promise<SheetRef>

copySheet(sheet)

Copies a sheet, places 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. Names are matched case-insensitively. Omitting sheet looks only at names used across the whole document.

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

Parameters

NameTypeDescription
namestringname to look up
sheet (optional)number | stringthe sheet, when the name is used only on that sheet

Returns

Name

getDefinedNameList(sheet)

Returns the list of defined names. Built-in names, hidden names, and names without a formula are excluded. Omitting sheet returns the names used across the whole document. formula starts with =.

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

Parameters

NameTypeDescription
sheet (optional)number | stringthe sheet, when the name is used only on that sheet

Returns

Promise<NameInfo[]>

getDocumentProperties()

Returns the document properties. A property the document does not carry is undefined.

getDocumentProperties(): Promise<DocumentProperties>;

Returns

Promise<DocumentProperties>

getObjectById(oid)

Returns an object handle by ID. It searches every sheet in the document and currently supports chart objects only; a non-chart object returns null.

getObjectById(oid: string): Chart;

Parameters

NameTypeDescription
oidstringunique ID that identifies the object

Returns

Chart

getSheetList()

Returns the document's sheet layout as an array. The array index is the sheet index (0-based) and hidden sheets are included. Read each sheet's detailed properties from Worksheet.

getSheetList(): Promise<SheetSummary[]>;

Returns

Promise<SheetSummary[]>

getTable(name)

Returns a table handle by name. Names are matched case-insensitively, and the handle carries the table name as stored.

getTable(name: string): Table;

Parameters

NameTypeDescription
namestringtable name; unique across the document

Returns

Table

getWorksheet(sheet)

Returns a sheet handle. A sheet name is matched case-sensitively. Omitting sheet targets the active sheet.

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 a sheet's position.

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

Parameters

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

Returns

Promise<void>

removeSheet(sheet)

Deletes a sheet. When the active sheet is deleted, an adjacent sheet becomes active. It cannot be deleted when only one sheet, or only one visible sheet, remains.

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

Parameters

NameTypeDescription
sheetnumber | stringsheet to delete

Returns

Promise<void>

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

Promise<void>