Excel.Binding class

Represents an Office.js binding that is defined in the workbook.

[ API set: ExcelApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

id

Represents binding identifier. Read-only.

[ API set: ExcelApi 1.1 ]

type

Returns the type of the binding. See Excel.BindingType for details. Read-only.

[ API set: ExcelApi 1.1 ]

Methods

delete()

Deletes the binding.

[ API set: ExcelApi 1.3 ]

getRange()

Returns the range represented by the binding. Will throw an error if binding is not of the correct type.

[ API set: ExcelApi 1.1 ]

getTable()

Returns the table represented by the binding. Will throw an error if binding is not of the correct type.

[ API set: ExcelApi 1.1 ]

getText()

Returns the text represented by the binding. Will throw an error if binding is not of the correct type.

[ API set: ExcelApi 1.1 ]

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

toJSON()

Events

onDataChanged

Occurs when data or formatting within the binding is changed.

[ API set: ExcelApi 1.2 ]

onSelectionChanged

Occurs when the selected content in the binding is changed.

[ API set: ExcelApi 1.2 ]

Property Details

id

Represents binding identifier. Read-only.

[ API set: ExcelApi 1.1 ]

readonly id: string;
Property Value
string

type

Returns the type of the binding. See Excel.BindingType for details. Read-only.

[ API set: ExcelApi 1.1 ]

readonly type: Excel.BindingType | "Range" | "Table" | "Text";
Property Value
Excel.BindingType | "Range" | "Table" | "Text"

Method Details

delete()

Deletes the binding.

[ API set: ExcelApi 1.3 ]

delete(): void;
Returns
void

getRange()

Returns the range represented by the binding. Will throw an error if binding is not of the correct type.

[ API set: ExcelApi 1.1 ]

getRange(): Excel.Range;
Returns

Examples

Excel.run(function (ctx) { 
    var binding = ctx.workbook.bindings.getItemAt(0);
    var range = binding.getRange();
    range.load('cellCount');
    return ctx.sync().then(function() {
        console.log(range.cellCount);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getTable()

Returns the table represented by the binding. Will throw an error if binding is not of the correct type.

[ API set: ExcelApi 1.1 ]

getTable(): Excel.Table;
Returns

Examples

Excel.run(function (ctx) { 
    var binding = ctx.workbook.bindings.getItemAt(0);
    var table = binding.getTable();
    table.load('name');
    return ctx.sync().then(function() {
            console.log(table.name);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getText()

Returns the text represented by the binding. Will throw an error if binding is not of the correct type.

[ API set: ExcelApi 1.1 ]

getText(): OfficeExtension.ClientResult<string>;
Returns
OfficeExtension.ClientResult<string>

Examples

Excel.run(function (ctx) { 
    var binding = ctx.workbook.bindings.getItemAt(0);
    var text = binding.getText();
    binding.load('text');
    return ctx.sync().then(function() {
        console.log(text);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(option?: string | string[]): Excel.Binding;
Parameters
option
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns
Remarks

In addition to this signature, this method has the following signatures:

load(option?: { select?: string; expand?: string; }): Excel.Binding - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.Binding - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

Examples

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

toJSON()

toJSON(): Excel.Interfaces.BindingData;
Returns

Event Details

onDataChanged

Occurs when data or formatting within the binding is changed.

[ API set: ExcelApi 1.2 ]

readonly onDataChanged: OfficeExtension.EventHandlers<Excel.BindingDataChangedEventArgs>;
Returns
OfficeExtension.EventHandlers<Excel.BindingDataChangedEventArgs>

Examples

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");    
    const salesTable = sheet.tables.getItem("SalesTable");
    const salesByQuarterBinding = context.workbook.bindings.add(salesTable.getRange(), "Table", "SalesByQuarter");
    salesByQuarterBinding.onDataChanged.add(onSalesDataChanged);

    OfficeHelpers.UI.notify("The handler is registered.", "Change the value in one of the data cells and watch this message banner. (Be sure to complete the edit by pressing Enter or clicking in another cell.)");

    await context.sync();
});

onSelectionChanged

Occurs when the selected content in the binding is changed.

[ API set: ExcelApi 1.2 ]

readonly onSelectionChanged: OfficeExtension.EventHandlers<Excel.BindingSelectionChangedEventArgs>;
Returns
OfficeExtension.EventHandlers<Excel.BindingSelectionChangedEventArgs>