Excel.Binding class
Represents an Office.js binding that is defined in the workbook.
- Extends
context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
id | Represents the binding identifier. |
type | Returns the type of the binding. See |
delete() | Deletes the binding. |
get |
Returns the range represented by the binding. Will throw an error if the binding is not of the correct type. |
get |
Returns the table represented by the binding. Will throw an error if the binding is not of the correct type. |
get |
Returns the text represented by the binding. Will throw an error if the binding is not of the correct type. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
toJSON() | Overrides the JavaScript |
on |
Occurs when data or formatting within the binding is changed. |
on |
Occurs when the selected content in the binding is changed. Note*: If multiple, discontiguous cells are selected, |
The request context associated with the object. This connects the add-in's process to the Office host application's process.
context: RequestContext;
Property Value
Represents the binding identifier.
readonly id: string;
Property Value
string
Remarks
Returns the type of the binding. See Excel.BindingType
for details.
readonly type: Excel.BindingType | "Range" | "Table" | "Text";
Property Value
Excel.BindingType | "Range" | "Table" | "Text"
Remarks
Returns the range represented by the binding. Will throw an error if the binding is not of the correct type.
getRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const binding = context.workbook.bindings.getItemAt(0);
const range = binding.getRange();
range.load('cellCount');
await context.sync();
console.log(range.cellCount);
});
Returns the table represented by the binding. Will throw an error if the binding is not of the correct type.
getTable(): Excel.Table;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const binding = context.workbook.bindings.getItemAt(0);
const table = binding.getTable();
table.load('name');
await context.sync();
console.log(table.name);
});
Returns the text represented by the binding. Will throw an error if the binding is not of the correct type.
getText(): OfficeExtension.ClientResult<string>;
Returns
OfficeExtension.ClientResult<string>
Remarks
Examples
await Excel.run(async (context) => {
const binding = context.workbook.bindings.getItemAt(0);
const text = binding.getText();
binding.load('text');
await context.sync();
console.log(text);
});
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(options?: Excel.Interfaces.BindingLoadOptions): Excel.Binding;
Parameters
Provides options for which properties of the object to load.
Returns
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNames?: string | string[]): Excel.Binding;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
Examples
await Excel.run(async (context) => {
const binding = context.workbook.bindings.getItemAt(0);
binding.load('type');
await context.sync();
console.log(binding.type);
});
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Excel.Binding;
Parameters
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select
is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand
is a comma-delimited string that specifies the navigation properties to load.
Returns
Overrides the JavaScript toJSON()
method in order to provide more useful output when an API object is passed to JSON.stringify()
. (JSON.stringify
, in turn, calls the toJSON
method of the object that's passed to it.) Whereas the original Excel.Binding
object is an API object, the toJSON
method returns a plain JavaScript object (typed as Excel.Interfaces.BindingData
) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Excel.Interfaces.BindingData;
Returns
Occurs when data or formatting within the binding is changed.
readonly onDataChanged: OfficeExtension.EventHandlers<Excel.BindingDataChangedEventArgs>;
Event Type
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/data-changed.yaml
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);
console.log("The data changed handler is registered.");
await context.sync();
});
Occurs when the selected content in the binding is changed.
Note*: If multiple, discontiguous cells are selected, Binding.onSelectionChanged
only reports row and column information for one selection. Use Worksheet.onSelectionChanged
for multiple selected ranges.
readonly onSelectionChanged: OfficeExtension.EventHandlers<Excel.BindingSelectionChangedEventArgs>;
Event Type
Remarks
Office Add-ins feedback
Office Add-ins is an open source project. Select a link to provide feedback: