Skip to content

Latest commit

 

History

History
231 lines (177 loc) · 5.42 KB

table.md

File metadata and controls

231 lines (177 loc) · 5.42 KB

Table

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.

Relationships

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.

Methods

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.

API Specification

delete()

Deletes the table.

Syntax

tableObject.delete();

Parameters

None

Returns

void

Examples

var tableName = 'Table1';
var ctx = new Excel.RequestContext();
var table = ctx.workbook.tables.getItem(tableName);
table.delete();
ctx.executeAsync();

Back

getDataBodyRange()

Gets the range object associated with the data body of the table.

Syntax

tableObject.getDataBodyRange();

Parameters

None

Returns

Range

Examples

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

Back

getHeaderRowRange()

Gets the range object associated with header row of the table.

Syntax

tableObject.getHeaderRowRange();

Parameters

None

Returns

Range

Examples

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

Back

getRange()

Gets the range object associated with the entire table.

Syntax

tableObject.getRange();

Parameters

None

Returns

Range

Examples

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

Back

getTotalRowRange()

Gets the range object associated with totals row of the table.

Syntax

tableObject.getTotalRowRange();

Parameters

None

Returns

Range

Examples

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

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 and Setter Examples

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

Back