Represents the collection of all the binding objects that are part of the workbook.
Property | Type | Description |
---|---|---|
count | int | Returns the number of bindings in the collection. Read-only. |
items | Binding[] | A collection of binding objects. Read-only. |
None
Method | Return Type | Description |
---|---|---|
getItem(id: string) | Binding | Gets a binding object by ID. |
getItemAt(index: number) | Binding | Gets a binding object based on its position in the items array. |
load(param: object) | void | Fills the proxy object created in JavaScript layer with property and object values specified in the parameter. |
Gets a binding object by ID.
bindingCollectionObject.getItem(id);
Parameter | Type | Description |
---|---|---|
id | string | Id of the binding object to be retrieved. |
Create a table binding to monitor data changes in the table. When data is changed, the background color of the table will be changed to orange.
function addEventHandler() {
//Create Table1
var ctx = new Excel.RequestContext();
ctx.workbook.tables.add("Sheet1!A1:C4", true);
ctx.executeAsync()
.then(function () {
console.log("My Diet Data Inserted!");
})
.catch(function (error) {
console.log(JSON.stringify(error));
});
//Create a new table binding for Table1
Office.context.document.bindings.addFromNamedItemAsync("Table1", Office.CoercionType.Table, { id: "myBinding" }, function (asyncResult) {
if (asyncResult.status == "failed") {
console.log("Action failed with error: " + asyncResult.error.message);
}
else {
// If succeeded, then add event handler to the table binding.
Office.select("bindings#myBinding").addHandlerAsync(Office.EventType.BindingDataChanged, onBindingDataChanged);
}
});
}
// when data in the table is changed, this event will be triggered.
function onBindingDataChanged(eventArgs) {
var ctx = new Excel.RequestContext();
// highlight the table in orange to indicate data has been changed.
ctx.workbook.bindings.getItem(eventArgs.binding.id).getTable().getDataBodyRange().format.fill.color = "Orange";
ctx.executeAsync()
.then(function () {
console.log("The value in this table got changed!");
})
.catch(function (error) {
console.log(JSON.stringify(error));
});
}
Gets a binding object based on its position in the items array.
bindingCollectionObject.getItemAt(index);
Parameter | Type | Description |
---|---|---|
index | number | Index value of the object to be retrieved. Zero-indexed. |
var ctx = new Excel.RequestContext();
var lastPosition = ctx.workbook.bindings.count - 1;
var binding = ctx.workbook.bindings.getItemAt(lastPosition);
ctx.executeAsync().then(function () {
Console.log(binding.type);
});
Fills the proxy object created in JavaScript layer with property and object values specified in the parameter.
object.load(param);
Parameter | Type | Description |
---|---|---|
param | object | Optional. Accepts parameter and relationship names as delimited string or an array. Or, provide loadOption object. |
void
var ctx = new Excel.RequestContext();
var bindings = ctx.workbook.bindings;
ctx.load(bindings);
ctx.executeAsync().then(function () {
for (var i = 0; i < bindings.items.length; i++)
{
Console.log(bindings.items[i].id);
Console.log(bindings.items[i].index);
}
});
Get the number of bindings
var ctx = new Excel.RequestContext();
var bindings = ctx.workbook.bindings;
ctx.load(bindings);
ctx.executeAsync().then(function () {
Console.log("Bindings: Count= " + bindings.count);
});