A format object encapsulating the range's font, fill, borders, alignment, and other properties.
Property | Type | Description |
---|---|---|
horizontalAlignment | string | Represents the horizontal alignment for the specified object. Possible values are: General, Left, Center, Right, Fill, Justify, CenterAcrossSelection, Distributed. |
verticalAlignment | string | Represents the vertical alignment for the specified object. Possible values are: Top, Center, Bottom, Justify, Distributed. |
wrapText | bool | Indicates if Excel wraps the text in the object. A null value indicates that the entire range doesn't have uniform wrap setting |
Relationship | Type | Description |
---|---|---|
borders | RangeBorderCollection | Collection of border objects that apply to the overall range selected Read-only. |
fill | RangeFill | Returns the fill object defined on the overall range. Read-only. |
font | RangeFont | Returns the font object defined on the overall range selected Read-only. |
Method | Return Type | Description |
---|---|---|
load(param: object) | void | Fills the proxy object created in JavaScript layer with property and object values specified in the parameter. |
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
Below example selects all of the Range's format properties.
var sheetName = "Sheet1";
var rangeAddress = "F:G";
var ctx = new Excel.RequestContext();
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
var range = worksheet.getRange(rangeAddress);
ctx.load(range, {expand: "fill, borders, font"} );
ctx.executeAsync().then(function() {
Console.log(range.format.wrapText);
Console.log(range.format.fill.color);
Console.log(range.format.font.name);
Console.log(range.format.borders.getItem('InsideHorizontal').lineStyle;
});
The example below sets font name, fill color and wraps text.
var sheetName = "Sheet1";
var rangeAddress = "F:G";
var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeAddress);
range.format.wrapText = true;
range.format.font.name = 'Times New Roman';
range.format.fill.color = '0000FF';
ctx.executeAsync();
The example below adds grid border around the range.
var sheetName = "Sheet1";
var rangeAddress = "F:G";
var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeAddress);
range.format.borders('InsideHorizontal').lineStyle = 'Continuous';
range.format.borders('InsideVertical').lineStyle = 'Continuous';
range.format.borders('EdgeBottom').lineStyle = 'Continuous';
range.format.borders('EdgeLeft').lineStyle = 'Continuous';
range.format.borders('EdgeRight').lineStyle = 'Continuous';
range.format.borders('EdgeTop').lineStyle = 'Continuous';
ctx.executeAsync();