Excel.TableColumnCollection class

Represents a collection of all the columns that are part of the table.

[ API set: ExcelApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

count

Returns the number of columns in the table. Read-only.

[ API set: ExcelApi 1.1 ]

items

Gets the loaded child items in this collection.

Methods

add(index, values, name)

Adds a new column to the table.

[ API set: ExcelApi 1.1 requires an index smaller than the total column count; 1.4 allows index to be optional (null or -1) and will append a column at the end; 1.4 allows name parameter at creation time. ]

getCount()

Gets the number of columns in the table.

[ API set: ExcelApi 1.4 ]

getItem(key)

Gets a column object by Name or ID.

[ API set: ExcelApi 1.1 ]

getItemAt(index)

Gets a column based on its position in the collection.

[ API set: ExcelApi 1.1 ]

getItemOrNullObject(key)

Gets a column object by Name or ID. If the column does not exist, will return a null object.

[ API set: ExcelApi 1.4 ]

load(option)

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

toJSON()

Property Details

count

Returns the number of columns in the table. Read-only.

[ API set: ExcelApi 1.1 ]

readonly count: number;
Property Value
number

items

Gets the loaded child items in this collection.

readonly items: Excel.TableColumn[];
Property Value
Excel.TableColumn[]

Method Details

add(index, values, name)

Adds a new column to the table.

[ API set: ExcelApi 1.1 requires an index smaller than the total column count; 1.4 allows index to be optional (null or -1) and will append a column at the end; 1.4 allows name parameter at creation time. ]

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 2-dimensional 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

Examples

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

getCount()

Gets the number of columns in the table.

[ API set: ExcelApi 1.4 ]

getCount(): OfficeExtension.ClientResult<number>;
Returns
OfficeExtension.ClientResult<number>

getItem(key)

Gets a column object by Name or ID.

[ API set: ExcelApi 1.1 ]

getItem(key: number | string): Excel.TableColumn;
Parameters
key
number | string

Column Name or ID.

Returns

Examples

Excel.run(function (ctx) { 
    var tablecolumn = ctx.workbook.tables.getItem('Table1').columns.getItem(0);
    tablecolumn.load('name');
    return ctx.sync().then(function() {
            console.log(tablecolumn.name);
    });
}).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 tablecolumn = ctx.workbook.tables.getItem['Table1'].columns.getItemAt(0);
    tablecolumn.load('name');
    return ctx.sync().then(function() {
            console.log(tablecolumn.name);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getItemAt(index)

Gets a column based on its position in the collection.

[ API set: ExcelApi 1.1 ]

getItemAt(index: number): Excel.TableColumn;
Parameters
index
number

Index value of the object to be retrieved. Zero-indexed.

Returns

Examples

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

getItemOrNullObject(key)

Gets a column object by Name or ID. If the column does not exist, will return a null object.

[ API set: ExcelApi 1.4 ]

getItemOrNullObject(key: number | string): Excel.TableColumn;
Parameters
key
number | string

Column Name or ID.

Returns

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?: string | string[]): Excel.TableColumnCollection;
Parameters
option
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns
Remarks

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

load(option?: { select?: string; expand?: string; }): Excel.TableColumnCollection - 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.TableColumnCollection - 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.

Examples

Excel.run(function (ctx) { 
    var tablecolumns = ctx.workbook.tables.getItem('Table1').columns;
    tablecolumns.load('items');
    return ctx.sync().then(function() {
        console.log("tablecolumns Count: " + tablecolumns.count);
        for (var i = 0; i < tablecolumns.items.length; i++)
        {
            console.log(tablecolumns.items[i].name);
        }
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

toJSON()

toJSON(): Excel.Interfaces.TableColumnCollectionData;
Returns