Skip to content

Latest commit

 

History

History
165 lines (121 loc) · 4.27 KB

tablecollection.md

File metadata and controls

165 lines (121 loc) · 4.27 KB

TableCollection

Represents a collection of all the tables that are part of the workbook.

Property Type Description
count int Returns the number of tables in the workbook. Read-only.
items Table[] A collection of table objects. Read-only.

Relationships

None

Methods

Method Return Type Description
add(address: string, hasHeaders: bool) Table Create a new table. The range source address determines the worksheet under which the table will be added. If the table cannot be added (e.g., because the address is invalid, or the table would overlap with another table), an error will be thrown.
getItem(id: object) Table Gets a table by Name or ID.
getItemAt(index: number) Table Gets a table based on its position in the collection.
load(param: object) void Fills the proxy object created in JavaScript layer with property and object values specified in the parameter.

API Specification

add(address: string, hasHeaders: bool)

Create a new table. The range source address determines the worksheet under which the table will be added. If the table cannot be added (e.g., because the address is invalid, or the table would overlap with another table), an error will be thrown.

Syntax

tableCollectionObject.add(address, hasHeaders);

Parameters

Parameter Type Description
address string Address or name of the range object representing the data source. If the address does not contain a sheet name, the currently-active sheet is used.
hasHeaders bool Boolean value that indicates whether the data being imported has column labels. If the source does not contain headers (i.e,. when this property set to false), Excel will automatically generate header shifting the data down by one row.

Returns

Table

Examples

var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.add('Sheet1!A1:E7', true);
ctx.load(table);
ctx.executeAsync().then(function () {
	Console.log(table.name);
});

Back

getItem(id: object)

Gets a table by Name or ID.

Syntax

tableCollectionObject.getItem(id);

Parameters

Parameter Type Description
id object Name or ID of the table to be retrieved.

Returns

Table

Examples

var ctx = new Excel.RequestContext();
var tableName = 'Table1';
var table = ctx.workbook.tables.getItem(tableName);
ctx.executeAsync().then(function () {
		Console.log(table.index);
});

Back

getItemAt(index: number)

Gets a table based on its position in the collection.

Syntax

tableCollectionObject.getItemAt(index);

Parameters

Parameter Type Description
index number Index value of the object to be retrieved. Zero-indexed.

Returns

Table

Examples

var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.getItemAt(0);
ctx.executeAsync().then(function () {
		Console.log(table.name);
});

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 tables = ctx.workbook.tables;
ctx.load(tables);
ctx.executeAsync().then(function () {
	Console.log("tables Count: " + tables.count);
	for (var i = 0; i < tables.items.length; i++)
	{
		Console.log(tables.items[i].name);
	}
});

Get the number of tables

var ctx = new Excel.RequestContext();
var tables = ctx.workbook.tables;
ctx.load(tables);
ctx.executeAsync().then(function () {
	
});

Back