Workbook Object (JavaScript API for Excel)

Workbook is the top level object which contains related workbook objects such as worksheets, tables, ranges, etc.

Properties

Property Type Description Req. Set
name string Gets the workbook name. Read-only. 1.7

Relationships

Relationship Type Description Req. Set
application Application Represents the Excel application instance that contains this workbook. Read-only. 1.1
bindings BindingCollection Represents a collection of bindings that are part of the workbook. Read-only. 1.1
customXmlParts CustomXmlPartCollection Represents the collection of custom XML parts contained by this workbook. Read-only. 1.5
dataConnections DataConnectionCollection Refreshes all data connections in the workbook. Read-only. 1.7
functions Functions Represents a collection of worksheet functions that can be used for computation. Read-only. 1.2
internalTest InternalTest For internal use only. Read-only. 1.6
names NamedItemCollection Represents a collection of workbook scoped named items (named ranges and constants). Read-only. 1.1
pivotTables PivotTableCollection Represents a collection of PivotTables associated with the workbook. Read-only. 1.3
properties DocumentProperties Gets the workbook properties. Read-only. 1.7
protection WorkbookProtection Returns workbook protection object for a workbook. Read-only. 1.7
settings SettingCollection Represents a collection of Settings associated with the workbook. Read-only. 1.4
styles StyleCollection Represents a collection of styles associated with the workbook. Read-only. 1.7
tables TableCollection Represents a collection of tables associated with the workbook. Read-only. 1.1
worksheets WorksheetCollection Represents a collection of worksheets associated with the workbook. Read-only. 1.1

Events

Event Description Event Argument Req. Set
onSelectionChanged The active or selected cell is changed. SelectionChangedEventArgs 1.2

Methods

Method Return Type Description Req. Set
getActiveCell() Range Gets the currently active cell from the workbook. 1.7
getSelectedRange() Range Gets the currently selected range from the workbook. 1.1

Method Details

getActiveCell()

Gets the currently active cell from the workbook.

Syntax

workbookObject.getActiveCell();

Parameters

None

Returns

Range

getSelectedRange()

Gets the currently selected range from the workbook.

Syntax

workbookObject.getSelectedRange();

Parameters

None

Returns

Range

Examples

Excel.run(function (ctx) { 
    var selectedRange = ctx.workbook.getSelectedRange();
    selectedRange.load('address');
    return ctx.sync().then(function() {
            console.log(selectedRange.address);
    });
}).catch(function(error) {
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));
        }
});