Skip to content

Latest commit

 

History

History
155 lines (113 loc) · 3.7 KB

worksheetcollection.md

File metadata and controls

155 lines (113 loc) · 3.7 KB

WorksheetCollection

Represents a collection of worksheet objects that are part of the workbook.

Property Type Description
items Worksheet[] A collection of worksheet objects. Read-only.

Relationships

None

Methods

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.

API Specification

add(name: string)

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.

Syntax

worksheetCollectionObject.add(name);

Parameters

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.

Returns

Worksheet

Examples

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);
});

Back

getActiveWorksheet()

Gets the currently active worksheet in the workbook.

Syntax

worksheetCollectionObject.getActiveWorksheet();

Parameters

None

Returns

Worksheet

Examples

hellow!!!
var ctx = new Excel.RequestContext(); 
var activeWorksheet = ctx.workbook.worksheets.getActiveWorksheet();
ctx.load(activeWorksheet);
ctx.executeAsync().then(function () {
		Console.log(activeWorksheet.name);
});

Back

getItem(index: string)

Gets a worksheet object using its Name or ID.

Syntax

worksheetCollectionObject.getItem(index);

Parameters

Parameter Type Description
index string The Name or ID of the worksheet.

Returns

Worksheet

Examples

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);
});

Back

load(param: object)

Fills the proxy object created in JavaScript layer with property and object values specified in the parameter.

Syntax

object.load(param);

Parameters

Parameter Type Description
param object Optional. Accepts parameter and relationship names as delimited string or an array. Or, provide loadOption object.

Returns

void

Examples

Back

Getter Examples

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);
	}
});

Back