Reference collection allows add-ins to add and remove temporary references on range.
None.
None
The Reference collection has the following methods defined:
Method | Return Type | Description | Notes |
---|---|---|---|
add(rangeObject: Range) | Null | Creates a new reference on a range. | |
remove(rangeObject: Range) | Null | Remove a reference on the range. |
Add a range object to the reference collection.
referenceCollection.add(rangeObject);
Parameter | Type | Description |
---|---|---|
rangeObject |
Range | The Range Object which needs to be added to the reference collection. |
Null
var sheetName = "Sheet1";
var rangeAddress = "A1:B2";
var ctx = new Excel.RequestContext();
var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeAddress);
ctx.references.add(range);
ctx.load(range);
ctx.executeAsync().then(function () {
range.insert("Down");
Console.log(range.address); // Address should be updated to A3:B4
ctx.executeAsync().then();
});
Remove a reference object from the collection.
referenceCollection.remove(rangeObject);
Parameter | Type | Description |
---|---|---|
rangeObject |
Range | The Range Object which needs to be removed from the reference collection. |
Null
```js
var sheetName = "Sheet1";
var rangeAddress = "A1:B2";
var ctx = new Excel.RequestContext();
var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeAddress);
ctx.references.add(range);
ctx.load(range);
ctx.executeAsync().then(function () {
range.insert("Down");
Console.log(range.address); // Address should be updated to A3:B4
ctx.references.remove(range);
ctx.executeAsync().then();
});