Excel.Table class
Represents an Excel table. To learn more about the table object model, read Work with tables using the Excel JavaScript API.
- Extends
Remarks
Properties
columns | Represents a collection of all the columns in the table. |
context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
id | 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. |
name | Name of the table. The set name of the table must follow the guidelines specified in the Rename an Excel table article. |
rows | Represents a collection of all the rows in the table. |
show |
Specifies if the header row is visible. This value can be set to show or remove the header row. |
show |
Specifies if the total row is visible. This value can be set to show or remove the total row. |
style | Constant value that represents the table style. Possible values are: "TableStyleLight1" through "TableStyleLight21", "TableStyleMedium1" through "TableStyleMedium28", "TableStyleDark1" through "TableStyleDark11". A custom user-defined style present in the workbook can also be specified. |
Methods
delete() | Deletes the table. |
get |
Gets the range object associated with the data body of the table. |
get |
Gets the range object associated with the header row of the table. |
get |
Gets the range object associated with the entire table. |
get |
Gets the range object associated with the totals row of the table. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
set(properties, options) | Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type. |
set(properties) | Sets multiple properties on the object at the same time, based on an existing loaded object. |
toJSON() | Overrides the JavaScript |
Property Details
columns
Represents a collection of all the columns in the table.
readonly columns: Excel.TableColumnCollection;
Property Value
Remarks
context
The request context associated with the object. This connects the add-in's process to the Office host application's process.
context: RequestContext;
Property Value
id
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.
readonly id: string;
Property Value
string
Remarks
name
Name of the table.
The set name of the table must follow the guidelines specified in the Rename an Excel table article.
name: string;
Property Value
string
Remarks
rows
Represents a collection of all the rows in the table.
readonly rows: Excel.TableRowCollection;
Property Value
Remarks
showHeaders
Specifies if the header row is visible. This value can be set to show or remove the header row.
showHeaders: boolean;
Property Value
boolean
Remarks
showTotals
Specifies if the total row is visible. This value can be set to show or remove the total row.
showTotals: boolean;
Property Value
boolean
Remarks
style
Constant value that represents the table style. Possible values are: "TableStyleLight1" through "TableStyleLight21", "TableStyleMedium1" through "TableStyleMedium28", "TableStyleDark1" through "TableStyleDark11". A custom user-defined style present in the workbook can also be specified.
style: string;
Property Value
string
Remarks
Examples
// Set table style.
await Excel.run(async (context) => {
const tableName = 'Table1';
const table = context.workbook.tables.getItem(tableName);
table.name = 'Table1-Renamed';
table.showTotals = false;
table.style = 'TableStyleMedium2';
table.load('tableStyle');
await context.sync();
console.log(table.style);
});
Method Details
delete()
Deletes the table.
delete(): void;
Returns
void
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const table = context.workbook.tables.getItem(tableName);
table.delete();
await context.sync();
});
getDataBodyRange()
Gets the range object associated with the data body of the table.
getDataBodyRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const table = context.workbook.tables.getItem(tableName);
const tableDataRange = table.getDataBodyRange();
tableDataRange.load('address')
await context.sync();
console.log(tableDataRange.address);
});
getHeaderRowRange()
Gets the range object associated with the header row of the table.
getHeaderRowRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const table = context.workbook.tables.getItem(tableName);
const tableHeaderRange = table.getHeaderRowRange();
tableHeaderRange.load('address');
await context.sync();
console.log(tableHeaderRange.address);
});
getRange()
Gets the range object associated with the entire table.
getRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const table = context.workbook.tables.getItem(tableName);
const tableRange = table.getRange();
tableRange.load('address');
await context.sync();
console.log(tableRange.address);
});
getTotalRowRange()
Gets the range object associated with the totals row of the table.
getTotalRowRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const table = context.workbook.tables.getItem(tableName);
const tableTotalsRange = table.getTotalRowRange();
tableTotalsRange.load('address');
await context.sync();
console.log(tableTotalsRange.address);
});
load(options)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(options?: Excel.Interfaces.TableLoadOptions): Excel.Table;
Parameters
Provides options for which properties of the object to load.
Returns
load(propertyNames)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNames?: string | string[]): Excel.Table;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
Examples
// Get a table by name.
await Excel.run(async (context) => {
const tableName = 'Table1';
const table = context.workbook.tables.getItem(tableName);
table.load('id')
await context.sync();
console.log(table.id);
});
load(propertyNamesAndPaths)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Excel.Table;
Parameters
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select
is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand
is a comma-delimited string that specifies the navigation properties to load.
Returns
set(properties, options)
Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.
set(properties: Interfaces.TableUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Excel.Interfaces.TableUpdateData
A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.
- options
- OfficeExtension.UpdateOptions
Provides an option to suppress errors if the properties object tries to set any read-only properties.
Returns
void
set(properties)
Sets multiple properties on the object at the same time, based on an existing loaded object.
set(properties: Excel.Table): void;
Parameters
- properties
- Excel.Table
Returns
void
toJSON()
Overrides the JavaScript toJSON()
method in order to provide more useful output when an API object is passed to JSON.stringify()
. (JSON.stringify
, in turn, calls the toJSON
method of the object that is passed to it.) Whereas the original Excel.Table
object is an API object, the toJSON
method returns a plain JavaScript object (typed as Excel.Interfaces.TableData
) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Excel.Interfaces.TableData;
Returns
Office Add-ins