Represents an Excel table.
Property | Type | Description |
---|---|---|
id | int | Returns a value that uniquely identifies the table in a given workbook. The value of the identifier remains the same even when the table is renamed. Read-only. |
name | string | Name of the table. |
showHeaders | bool | Indicates whether the header row is visible or not. This value can be set to show or remove the header row. |
showTotals | bool | Indicates whether the total row is visible or not. This value can be set to show or remove the total row. |
style | string | Constant value that represents the Table style. Possible values are: TableStyleLight1 thru TableStyleLight21, TableStyleMedium1 thru TableStyleMedium28, TableStyleStyleDark1 thru TableStyleStyleDark11. A custom user-defined style present in the workbook can also be specified. |
Relationship | Type | Description |
---|---|---|
columns | TableColumnCollection | Represents a collection of all the columns in the table. Read-only. |
rows | TableRowCollection | Represents a collection of all the rows in the table. Read-only. |
Method | Return Type | Description |
---|---|---|
delete() | void | Deletes the table. |
getDataBodyRange() | Range | Gets the range object associated with the data body of the table. |
getHeaderRowRange() | Range | Gets the range object associated with header row of the table. |
getRange() | Range | Gets the range object associated with the entire table. |
getTotalRowRange() | Range | Gets the range object associated with totals row of the table. |
load(param: object) | void | Fills the proxy object created in JavaScript layer with property and object values specified in the parameter. |
Deletes the table.
tableObject.delete();
None
void
var tableName = 'Table1';
var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.getItem(tableName);
table.delete();
ctx.executeAsync();
Gets the range object associated with the data body of the table.
tableObject.getDataBodyRange();
None
var tableName = 'Table1';
var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.getItem(tableName);
var tableDataRange = table.getDataBodyRange();
ctx.executeAsync().then(function () {
Console.log(tableDataRange.address);
});
Gets the range object associated with header row of the table.
tableObject.getHeaderRowRange();
None
var tableName = 'Table1';
var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.getItem(tableName);
var tableHeaderRange = table.getHeaderRowRange();
ctx.executeAsync().then(function () {
Console.log(tableHeaderRange.address);
});
Gets the range object associated with the entire table.
tableObject.getRange();
None
var tableName = 'Table1';
var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.getItem(tableName);
var tableRange = table.getRange();
ctx.executeAsync().then(function () {
Console.log(tableRange.address);
});
Gets the range object associated with totals row of the table.
tableObject.getTotalRowRange();
None
var tableName = 'Table1';
var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.getItem(tableName);
var tableTotalsRange = table.getTotalRowRange();
ctx.executeAsync().then(function () {
Console.log(tableTotalsRange.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 a table by name.
var ctx = new Excel.RequestContext();
var tableName = 'Table1';
var table = ctx.workbook.tables.getItem(tableName);
ctx.executeAsync().then(function () {
Console.log(table.index);
});
Get a table by index.
var ctx = new Excel.RequestContext();
var index = 0;
var table = ctx.workbook.tables.getItemAt(0);
ctx.executeAsync().then(function () {
Console.log(table.name);
});
Set table style.
var tableName = 'Table1';
var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.getItem(tableName);
table.name = 'Table1-Renamed';
table.showTotals = false;
table.tableStyle = 'TableStyleMedium2';
ctx.load(table);
ctx.executeAsync().then(function () {
Console.log(table.tableStyle);
});