Excel.TableColumnCollection class
Represents a collection of all the columns that are part of the table.
- Extends
Remarks
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 columns in the table. |
items | Gets the loaded child items in this collection. |
Methods
add(index, values, name) | Adds a new column to the table. |
add |
Adds a new column to the table. Unlike |
get |
Gets the number of columns in the table. |
get |
Gets a column object by name or ID. |
get |
Gets a column based on its position in the collection. |
get |
Gets a column object by name or ID. If the column 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 |
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 columns in the table.
readonly count: number;
Property Value
number
Remarks
items
Gets the loaded child items in this collection.
readonly items: Excel.TableColumn[];
Property Value
Method Details
add(index, values, name)
Adds a new column to the table.
add(index?: number, values?: Array<Array<boolean | string | number>> | boolean | string | number, name?: string): Excel.TableColumn;
Parameters
- index
-
number
Optional. Specifies the relative position of the new column. If null or -1, the addition happens at the end. Columns with a higher index will be shifted to the side. Zero-indexed.
- values
-
Array<Array<boolean | string | number>> | boolean | string | number
Optional. A 2D array of unformatted values of the table column.
- name
-
string
Optional. Specifies the name of the new column. If null
, the default name will be used.
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tables = context.workbook.tables;
const values = [["Sample"], ["Values"], ["For"], ["New"], ["Column"]];
const column = tables.getItem("Table1").columns.add(null, values);
column.load('name');
await context.sync();
console.log(column.name);
});
addAsJson(index, values, name)
Adds a new column to the table. Unlike add()
, addAsJson()
takes any type of cell value, such as image or entity data types.
addAsJson(index?: number, values?: CellValue[][], name?: string): Excel.TableColumn;
Parameters
- index
-
number
Optional. Specifies the relative position of the new column. If null or -1, the addition happens at the end. Columns with a higher index will be shifted to the side. Zero-indexed.
- values
-
Excel.CellValue[][]
Optional. A 2D array of cell values of the table column.
- name
-
string
Optional. Specifies the name of the new column. If null
, the default name will be used.
Returns
Remarks
getCount()
Gets the number of columns in the table.
getCount(): OfficeExtension.ClientResult<number>;
Returns
OfficeExtension.ClientResult<number>
Remarks
getItem(key)
Gets a column object by name or ID.
getItem(key: number | string): Excel.TableColumn;
Parameters
- key
-
number | string
Column name or ID.
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableColumn = context.workbook.tables.getItem('Table1').columns.getItem(0);
tableColumn.load('name');
await context.sync();
console.log(tableColumn.name);
});
getItemAt(index)
Gets a column based on its position in the collection.
getItemAt(index: number): Excel.TableColumn;
Parameters
- index
-
number
Index value of the object to be retrieved. Zero-indexed.
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableColumn = context.workbook.tables.getItem['Table1'].columns.getItemAt(0);
tableColumn.load('name');
await context.sync();
console.log(tableColumn.name);
});
getItemOrNullObject(key)
Gets a column object by name or ID. If the column 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: number | string): Excel.TableColumn;
Parameters
- key
-
number | string
Column name or ID.
Returns
Remarks
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.TableColumnCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.TableColumnCollection;
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.TableColumnCollection;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
Examples
await Excel.run(async (context) => {
const tableColumns = context.workbook.tables.getItem('Table1').columns;
tableColumns.load('items');
await context.sync();
console.log("tableColumns Count: " + tableColumns.count);
for (let i = 0; i < tableColumns.items.length; i++) {
console.log(tableColumns.items[i].name);
}
});
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.TableColumnCollection;
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 is passed to it.) Whereas the original Excel.TableColumnCollection
object is an API object, the toJSON
method returns a plain JavaScript object (typed as Excel.Interfaces.TableColumnCollectionData
) that contains an "items" array with shallow copies of any loaded properties from the collection's items.
toJSON(): Excel.Interfaces.TableColumnCollectionData;
Returns
Office Add-ins