An Excel worksheet is a grid of cells. It can contain data, tables, charts, etc.
Property | Type | Description |
---|---|---|
id | string | Returns a value that uniquely identifies the worksheet in a given workbook. The value of the identifier remains the same even when the worksheet is renamed or moved. Read-only. |
name | string | The display name of the worksheet. |
position | int | The zero-based position of the worksheet within the workbook. |
visibility | string | The Visibility of the worksheet, Read-only. Possible values are: Visible, Hidden, VeryHidden. |
Relationship | Type | Description |
---|---|---|
charts | ChartCollection | Returns collection of charts that are part of the worksheet. Read-only. |
tables | TableCollection | Collection of tables that are part of the worksheet. Read-only. |
Method | Return Type | Description |
---|---|---|
activate() | void | Activate the worksheet in the Excel UI. |
delete() | void | Deletes the worksheet from the workbook. |
getCell(row: number, column: number) | Range | Gets the range object containing the single cell based on row and column numbers. The cell can be outside the bounds of its parent range, so long as it's stays within the worksheet grid. |
getRange(address: string) | Range | Gets the range object specified by the address or name. |
getUsedRange() | Range | The used range is the smallest range than encompasses any cells that have a value or formatting assigned to them. If the worksheet is blank, this function will return the top left cell. |
load(param: object) | void | Fills the proxy object created in JavaScript layer with property and object values specified in the parameter. |
Activate the worksheet in the Excel UI.
worksheetObject.activate();
None
void
var ctx = new Excel.RequestContext();
var wSheetName = 'Sheet1';
var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
worksheet.activate();
ctx.executeAsync();
Deletes the worksheet from the workbook.
worksheetObject.delete();
None
void
var wSheetName = 'Sheet1';
var ctx = new Excel.RequestContext();
var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
worksheet.delete();
ctx.executeAsync();
Gets the range object containing the single cell based on row and column numbers. The cell can be outside the bounds of its parent range, so long as it's stays within the worksheet grid.
worksheetObject.getCell(row, column);
Parameter | Type | Description |
---|---|---|
row | number | The row number of the cell to be retrieved. Zero-indexed. |
column | number | the column number of the cell to be retrieved. Zero-indexed. |
var sheetName = "Sheet1";
var rangeAddress = "A1:F8";
var ctx = new Excel.RequestContext();
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
var cell = worksheet.getCell(0,0);
ctx.load(cell);
ctx.executeAsync().then(function() {
Console.log(cell.address);
});
Gets the range object specified by the address or name.
worksheetObject.getRange(address);
Parameter | Type | Description |
---|---|---|
address | string | Optional. The address or the name of the range. If not specified, the entire worksheet range is returned. |
Below example uses range address to get the range object.
var sheetName = "Sheet1";
var rangeAddress = "A1:F8";
var ctx = new Excel.RequestContext();
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
var range = worksheet.getRange(rangeAddress);
ctx.load(range);
ctx.executeAsync().then(function() {
Console.log(range.cellCount);
});
Below example uses a named-range to get the range object.
var sheetName = "Sheet1";
var rangeName = 'MyRange';
var ctx = new Excel.RequestContext();
var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeName);
ctx.load(range);
ctx.executeAsync().then(function() {
Console.log(range.address);
});
The used range is the smallest range than encompasses any cells that have a value or formatting assigned to them. If the worksheet is blank, this function will return the top left cell.
worksheetObject.getUsedRange();
None
var ctx = new Excel.RequestContext();
var wSheetName = 'Sheet1';
var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
var usedRange = worksheet.getUsedRange();
ctx.load(usedRange);
ctx.executeAsync().then(function () {
Console.log(usedRange.address);
});
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
Get worksheet properties based on sheet name.
var ctx = new Excel.RequestContext();
var wSheetName = 'Sheet1';
var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
ctx.executeAsync().then(function () {
Console.log(worksheet.index);
});
Set worksheet position.
var ctx = new Excel.RequestContext();
var wSheetName = 'Sheet1';
var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
worksheet.position = 0;
ctx.executeAsync();