Excel.TableColumn class
Represents a column in a 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. |
filter | Retrieves the filter applied to the column. |
id | Returns a unique key that identifies the column within the table. |
index | Returns the index number of the column within the columns collection of the table. Zero-indexed. |
name | Specifies the name of the table column. |
values | Represents the raw values of the specified range. The data returned could be a string, number, or boolean. Cells that contain an error will return the error string. If the returned value starts with a plus ("+"), minus ("-"), or equal sign ("="), Excel interprets this value as a formula. |
values |
A JSON representation of the values in the cells in this table column. Unlike |
values |
A JSON representation of the values in the cells in this table column. Unlike |
Methods
delete() | Deletes the column from the table. |
get |
Gets the range object associated with the data body of the column. |
get |
Gets the range object associated with the header row of the column. |
get |
Gets the range object associated with the entire column. |
get |
Gets the range object associated with the totals row of the column. |
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
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
filter
Retrieves the filter applied to the column.
readonly filter: Excel.Filter;
Property Value
Remarks
id
Returns a unique key that identifies the column within the table.
readonly id: number;
Property Value
number
Remarks
index
Returns the index number of the column within the columns collection of the table. Zero-indexed.
readonly index: number;
Property Value
number
Remarks
name
Specifies the name of the table column.
name: string;
Property Value
string
Remarks
[ API set: ExcelApi 1.1 for getting the name; 1.4 for setting it. ]
values
Represents the raw values of the specified range. The data returned could be a string, number, or boolean. Cells that contain an error will return the error string. If the returned value starts with a plus ("+"), minus ("-"), or equal sign ("="), Excel interprets this value as a formula.
values: any[][];
Property Value
any[][]
Remarks
valuesAsJson
A JSON representation of the values in the cells in this table column. Unlike TableColumn.values
, TableColumn.valuesAsJson
supports all data types which can be in a cell. Examples include formatted number values and web images, in addition to the standard boolean, number, and string values. Data returned from this API always aligns with the en-US locale. To retrieve data in the user's display locale, use TableColumn.valuesAsJsonLocal
.
valuesAsJson: CellValue[][];
Property Value
Excel.CellValue[][]
Remarks
valuesAsJsonLocal
A JSON representation of the values in the cells in this table column. Unlike TableColumn.values
, TableColumn.valuesAsJsonLocal
supports all data types which can be in a cell. Examples include formatted number values and web images, in addition to the standard boolean, number, and string values. Data returned from this API always aligns with the user's display locale. To retrieve data independent of locale, use TableColumn.valuesAsJson
.
valuesAsJsonLocal: CellValue[][];
Property Value
Excel.CellValue[][]
Remarks
Method Details
delete()
Deletes the column from the table.
delete(): void;
Returns
void
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const column = context.workbook.tables.getItem(tableName).columns.getItemAt(2);
column.delete();
await context.sync();
});
getDataBodyRange()
Gets the range object associated with the data body of the column.
getDataBodyRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const column = context.workbook.tables.getItem(tableName).columns.getItemAt(0);
const dataBodyRange = column.getDataBodyRange();
dataBodyRange.load('address');
await context.sync();
console.log(dataBodyRange.address);
});
getHeaderRowRange()
Gets the range object associated with the header row of the column.
getHeaderRowRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const columns = context.workbook.tables.getItem(tableName).columns.getItemAt(0);
const headerRowRange = columns.getHeaderRowRange();
headerRowRange.load('address');
await context.sync();
console.log(headerRowRange.address);
});
getRange()
Gets the range object associated with the entire column.
getRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const columns = context.workbook.tables.getItem(tableName).columns.getItemAt(0);
const columnRange = columns.getRange();
columnRange.load('address');
await context.sync();
console.log(columnRange.address);
});
getTotalRowRange()
Gets the range object associated with the totals row of the column.
getTotalRowRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const columns = context.workbook.tables.getItem(tableName).columns.getItemAt(0);
const totalRowRange = columns.getTotalRowRange();
totalRowRange.load('address');
await context.sync();
console.log(totalRowRange.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.TableColumnLoadOptions): Excel.TableColumn;
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.TableColumn;
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 tableName = 'Table1';
const column = context.workbook.tables.getItem(tableName).columns.getItem(0);
column.load('index');
await context.sync();
console.log(column.index);
});
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.TableColumn;
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.TableColumnUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Excel.Interfaces.TableColumnUpdateData
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.TableColumn): void;
Parameters
- properties
- Excel.TableColumn
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.TableColumn
object is an API object, the toJSON
method returns a plain JavaScript object (typed as Excel.Interfaces.TableColumnData
) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Excel.Interfaces.TableColumnData;
Returns
Office Add-ins