Represents a collection of worksheet objects that are part of the workbook.
Property | Type | Description |
---|---|---|
items | Worksheet[] | A collection of worksheet objects. Read-only. |
None
Method | Return Type | Description |
---|---|---|
add(name: string) | Worksheet | Adds a new worksheet to the workbook. The worksheet will be added at the end of existing worksheets. If you wish to activate the newly added worksheet, call ".activate() on it. |
getActiveWorksheet() | Worksheet | Gets the currently active worksheet in the workbook. |
getItem(index: string) | Worksheet | Gets a worksheet object using its Name or ID. |
load(param: object) | void | Fills the proxy object created in JavaScript layer with property and object values specified in the parameter. |
Adds a new worksheet to the workbook. The worksheet will be added at the end of existing worksheets. If you wish to activate the newly added worksheet, call ".activate() on it.
worksheetCollectionObject.add(name);
Parameter | Type | Description |
---|---|---|
name | string | Optional. The name of the worksheet to be added. If specified, name should be unqiue. If not specified, Excel determines the name of the new worksheet. |
var wSheetName = 'Sample Name';
var ctx = new Excel.RequestContext();
var worksheet = ctx.workbook.worksheets.add(wSheetName);
ctx.load(worksheet);
ctx.executeAsync().then(function () {
Console.log(worksheet.name);
});
Gets the currently active worksheet in the workbook.
worksheetCollectionObject.getActiveWorksheet();
None
hellow!!!
var ctx = new Excel.RequestContext();
var activeWorksheet = ctx.workbook.worksheets.getActiveWorksheet();
ctx.load(activeWorksheet);
ctx.executeAsync().then(function () {
Console.log(activeWorksheet.name);
});
Gets a worksheet object using its Name or ID.
worksheetCollectionObject.getItem(index);
Parameter | Type | Description |
---|---|---|
index | string | The Name or ID of the worksheet. |
var ctx = new Excel.RequestContext();
var wSheetName = 'Sheet1';
var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
ctx.load(worksheet);
ctx.executeAsync().then(function () {
Console.log(worksheet.index);
});
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
var ctx = new Excel.RequestContext();
var worksheets = ctx.workbook.worksheets;
ctx.load(worksheets);
ctx.executeAsync().then(function () {
for (var i = 0; i < worksheets.items.length; i++)
{
Console.log(worksheets.items[i].name);
Console.log(worksheets.items[i].index);
}
});