Excel.TableCollection class
Represents a collection of all the tables that are part of the workbook or worksheet, depending on how it was reached.
- Extends
Remarks
[Api set: ExcelApi 1.1]
Properties
| context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
| count | Returns the number of tables in the workbook. |
| items | Gets the loaded child items in this collection. |
Methods
| add(address, has |
Creates a new table. The range object or 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. |
| get |
Gets the number of tables in the collection. |
| get |
Gets a table by name or ID. |
| get |
Gets a table based on its position in the collection. |
| get |
Gets a table by name or ID. If the table doesn't exist, then this method returns an object with its |
| 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 |
| toJSON() | Overrides the JavaScript |
Events
| on |
Occurs when a new table is added in a workbook. |
| on |
Occurs when data changes on any table in a workbook, or a worksheet. |
| on |
Occurs when the specified table is deleted in a workbook. |
Property Details
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
count
Returns the number of tables in the workbook.
readonly count: number;
Property Value
number
Remarks
[Api set: ExcelApi 1.1]
items
Gets the loaded child items in this collection.
readonly items: Excel.Table[];
Property Value
Method Details
add(address, hasHeaders)
Creates a new table. The range object or 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.
add(address: Range | string, hasHeaders: boolean): Excel.Table;
Parameters
- address
-
Excel.Range | string
A Range object, or a string address or name of the range representing the data source. If the address does not contain a sheet name, the currently-active sheet is used. [Api set: ExcelApi 1.1 / 1.3. Prior to ExcelApi 1.3, this parameter must be a string. Starting with Excel Api 1.3, this parameter may be a Range object or a string.]
- hasHeaders
-
boolean
A 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 a header and shift the data down by one row.
Returns
Remarks
[Api set: ExcelApi 1.1]
getCount()
Gets the number of tables in the collection.
getCount(): OfficeExtension.ClientResult<number>;
Returns
OfficeExtension.ClientResult<number>
Remarks
[Api set: ExcelApi 1.4]
getItem(key)
Gets a table by name or ID.
getItem(key: string): Excel.Table;
Parameters
- key
-
string
Name or ID of the table to be retrieved.
Returns
Remarks
[Api set: ExcelApi 1.1]
getItemAt(index)
Gets a table based on its position in the collection.
getItemAt(index: number): Excel.Table;
Parameters
- index
-
number
Index value of the object to be retrieved. Zero-indexed.
Returns
Remarks
[Api set: ExcelApi 1.1]
getItemOrNullObject(key)
Gets a table by name or ID. If the table doesn't exist, then this method returns an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.
getItemOrNullObject(key: string): Excel.Table;
Parameters
- key
-
string
Name or ID of the table to be retrieved.
Returns
Remarks
[Api set: ExcelApi 1.4]
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.TableCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.TableCollection;
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.TableCollection;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
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?: OfficeExtension.LoadOption): Excel.TableCollection;
Parameters
- propertyNamesAndPaths
- OfficeExtension.LoadOption
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
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's passed to it.) Whereas the original Excel.TableCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.TableCollectionData) that contains an "items" array with shallow copies of any loaded properties from the collection's items.
toJSON(): Excel.Interfaces.TableCollectionData;
Returns
Event Details
onAdded
Occurs when a new table is added in a workbook.
readonly onAdded: OfficeExtension.EventHandlers<Excel.TableAddedEventArgs>;
Event Type
Remarks
[Api set: ExcelApi 1.9]
onChanged
Occurs when data changes on any table in a workbook, or a worksheet.
readonly onChanged: OfficeExtension.EventHandlers<Excel.TableChangedEventArgs>;
Event Type
Remarks
[Api set: ExcelApi 1.7]
onDeleted
Occurs when the specified table is deleted in a workbook.
readonly onDeleted: OfficeExtension.EventHandlers<Excel.TableDeletedEventArgs>;
Event Type
Remarks
[Api set: ExcelApi 1.9]