RangeBorderCollection Object (JavaScript API for Excel)
Represents the border objects that make up the range border.
Properties
Property | Type | Description | Req. Set |
---|---|---|---|
count | int | Number of border objects in the collection. Read-only. | 1.1 |
items | RangeBorder[] | A collection of rangeBorder objects. Read-only. | 1.1 |
See property access examples.
Relationships
None
Methods
Method | Return Type | Description | Req. Set |
---|---|---|---|
getItem(index: string) | RangeBorder | Gets a border object using its name | 1.1 |
getItemAt(index: number) | RangeBorder | Gets a border object using its index | 1.1 |
Method Details
getItem(index: string)
Gets a border object using its name
Syntax
rangeBorderCollectionObject.getItem(index);
Parameters
Parameter | Type | Description |
---|---|---|
index | string | Index value of the border object to be retrieved. Possible values are: EdgeTop, EdgeBottom, EdgeLeft, EdgeRight, InsideVertical, InsideHorizontal, DiagonalDown, DiagonalUp |
Returns
Examples
Excel.run(function (ctx) {
var sheetName = "Sheet1";
var rangeAddress = "A1:F8";
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
var range = worksheet.getRange(rangeAddress);
var borderName = 'EdgeTop';
var border = range.format.borders.getItem(borderName);
border.load('style');
return ctx.sync().then(function() {
console.log(border.style);
});
}).catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
Examples
Excel.run(function (ctx) {
var sheetName = "Sheet1";
var rangeAddress = "A1:F8";
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
var range = worksheet.getRange(rangeAddress);
var border = range.format.borders.getItemAt(0);
border.load('sideIndex');
return ctx.sync().then(function() {
console.log(border.sideIndex);
});
}).catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
getItemAt(index: number)
Gets a border object using its index
Syntax
rangeBorderCollectionObject.getItemAt(index);
Parameters
Parameter | Type | Description |
---|---|---|
index | number | Index value of the object to be retrieved. Zero-indexed. |
Returns
Examples
Excel.run(function (ctx) {
var sheetName = "Sheet1";
var rangeAddress = "A1:F8";
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
var range = worksheet.getRange(rangeAddress);
var border = range.format.borders.getItemAt(0);
border.load('sideIndex');
return ctx.sync().then(function() {
console.log(border.sideIndex);
});
}).catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
Property access examples
Excel.run(function (ctx) {
var sheetName = "Sheet1";
var rangeAddress = "A1:F8";
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
var range = worksheet.getRange(rangeAddress);
var borders = range.format.borders;
border.load('items');
return ctx.sync().then(function() {
console.log(borders.count);
for (var i = 0; i < borders.items.length; i++)
{
console.log(borders.items[i].sideIndex);
}
});
}).catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
The example below adds grid border around the range.
Excel.run(function (ctx) {
var sheetName = "Sheet1";
var rangeAddress = "A1:F8";
var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeAddress);
range.format.borders.getItem('InsideHorizontal').style = 'Continuous';
range.format.borders.getItem('InsideVertical').style = 'Continuous';
range.format.borders.getItem('EdgeBottom').style = 'Continuous';
range.format.borders.getItem('EdgeLeft').style = 'Continuous';
range.format.borders.getItem('EdgeRight').style = 'Continuous';
range.format.borders.getItem('EdgeTop').style = 'Continuous';
return ctx.sync();
}).catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});