Excel.Binding class
Represents an Office.js binding that is defined in the workbook.
- Extends
Remarks
Properties
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 |
Methods
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 |
Property Details
context
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
id
Represents the binding identifier.
readonly id: string;
Property Value
string
Remarks
type
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
Method Details
getRange()
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);
});
getTable()
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);
});
getText()
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);
});
load(options)
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
load(propertyNames)
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);
});
load(propertyNamesAndPaths)
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
toJSON()
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 is 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
Office Add-ins