Excel.TableColumn class

Represents a column in a table.

[ API set: ExcelApi 1.1 ]

Extends
OfficeExtension.ClientObject

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(options)

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

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

options
Excel.Interfaces.TableColumnLoadOptions

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

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

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