Excel.TableColumn class

Represents a column in a table.

[ API set: ExcelApi 1.1 ]

Extends

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

filter

Retrieve the filter applied to the column. Read-only.

[ API set: ExcelApi 1.2 ]

id

Returns a unique key that identifies the column within the table. Read-only.

[ API set: ExcelApi 1.1 ]

index

Returns the index number of the column within the columns collection of the table. Zero-indexed. Read-only.

[ API set: ExcelApi 1.1 ]

name

Represents the name of the table column.

[ 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 of type string, number, or a boolean. Cells that contain an error will return the error string.

[ API set: ExcelApi 1.1 ]

Methods

delete()

Deletes the column from the table.

[ API set: ExcelApi 1.1 ]

getDataBodyRange()

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

[ API set: ExcelApi 1.1 ]

getHeaderRowRange()

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

[ API set: ExcelApi 1.1 ]

getRange()

Gets the range object associated with the entire column.

[ API set: ExcelApi 1.1 ]

getTotalRowRange()

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

[ API set: ExcelApi 1.1 ]

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

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 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.

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

RequestContext

filter

Retrieve the filter applied to the column. Read-only.

[ API set: ExcelApi 1.2 ]

readonly filter: Excel.Filter;

Property Value

id

Returns a unique key that identifies the column within the table. Read-only.

[ API set: ExcelApi 1.1 ]

readonly id: number;

Property Value

number

index

Returns the index number of the column within the columns collection of the table. Zero-indexed. Read-only.

[ API set: ExcelApi 1.1 ]

readonly index: number;

Property Value

number

name

Represents the name of the table column.

[ API set: ExcelApi 1.1 for getting the name; 1.4 for setting it. ]

name: string;

Property Value

string

values

Represents the raw values of the specified range. The data returned could be of type string, number, or a boolean. Cells that contain an error will return the error string.

[ API set: ExcelApi 1.1 ]

values: any[][];

Property Value

any[][]

Method Details

delete()

Deletes the column from the table.

[ API set: ExcelApi 1.1 ]

delete(): void;

Returns

void

Examples

Excel.run(function (ctx) { 
    var tableName = 'Table1';
    var column = ctx.workbook.tables.getItem(tableName).columns.getItemAt(2);
    column.delete();
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getDataBodyRange()

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

[ API set: ExcelApi 1.1 ]

getDataBodyRange(): Excel.Range;

Returns

Examples

Excel.run(function (ctx) { 
    var tableName = 'Table1';
    var column = ctx.workbook.tables.getItem(tableName).columns.getItemAt(0);
    var dataBodyRange = column.getDataBodyRange();
    dataBodyRange.load('address');
    return ctx.sync().then(function() {
        console.log(dataBodyRange.address);
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getHeaderRowRange()

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

[ API set: ExcelApi 1.1 ]

getHeaderRowRange(): Excel.Range;

Returns

Examples

Excel.run(function (ctx) { 
    var tableName = 'Table1';
    var columns = ctx.workbook.tables.getItem(tableName).columns.getItemAt(0);
    var headerRowRange = columns.getHeaderRowRange();
    headerRowRange.load('address');
    return ctx.sync().then(function() {
        console.log(headerRowRange.address);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getRange()

Gets the range object associated with the entire column.

[ API set: ExcelApi 1.1 ]

getRange(): Excel.Range;

Returns

Examples

Excel.run(function (ctx) { 
    var tableName = 'Table1';
    var columns = ctx.workbook.tables.getItem(tableName).columns.getItemAt(0);
    var columnRange = columns.getRange();
    columnRange.load('address');
    return ctx.sync().then(function() {
        console.log(columnRange.address);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getTotalRowRange()

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

[ API set: ExcelApi 1.1 ]

getTotalRowRange(): Excel.Range;

Returns

Examples

Excel.run(function (ctx) { 
    var tableName = 'Table1';
    var columns = ctx.workbook.tables.getItem(tableName).columns.getItemAt(0);
    var totalRowRange = columns.getTotalRowRange();
    totalRowRange.load('address');
    return ctx.sync().then(function() {
        console.log(totalRowRange.address);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(option?: Excel.Interfaces.TableColumnLoadOptions): Excel.TableColumn;

Parameters

Returns

Remarks

In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Excel.TableColumn - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Excel.TableColumn - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.TableColumn - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

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

Excel.run(function (ctx) { 
    var tableName = 'Table1';
    var column = ctx.workbook.tables.getItem(tableName).columns.getItem(0);
    column.load('index');
    return ctx.sync().then(function() {
        console.log(column.index);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
Excel.run(function (ctx) { 
    var tableName = 'Table1';
    var tables = ctx.workbook.tables;
    var newValues = [["New"], ["Values"], ["For"], ["New"], ["Column"]];
    var column = ctx.workbook.tables.getItem(tableName).columns.getItemAt(2);
    column.values = newValues;
    column.load('values');
    return ctx.sync().then(function() {
        console.log(column.values);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

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

Where 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
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

Remarks

This method has the following additional signature:

set(properties: Excel.TableColumn): 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