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. |
None
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. |
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.
tableCollectionObject.add(address, hasHeaders);
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. |
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);
});
Gets a table by Name or ID.
tableCollectionObject.getItem(id);
Parameter | Type | Description |
---|---|---|
id | object | Name or ID of the table to be retrieved. |
var ctx = new Excel.RequestContext();
var tableName = 'Table1';
var table = ctx.workbook.tables.getItem(tableName);
ctx.executeAsync().then(function () {
Console.log(table.index);
});
Gets a table based on its position in the collection.
tableCollectionObject.getItemAt(index);
Parameter | Type | Description |
---|---|---|
index | number | Index value of the object to be retrieved. Zero-indexed. |
var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.getItemAt(0);
ctx.executeAsync().then(function () {
Console.log(table.name);
});
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 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 () {
});