OneNote.Table class

Represents a table in a OneNote page.

[ API set: OneNoteApi 1.1 ]

Extends

Properties

borderVisible

Gets or sets whether the borders are visible or not. True if they are visible, false if they are hidden.

[ API set: OneNoteApi 1.1 ]

columnCount

Gets the number of columns in the table.

[ API set: OneNoteApi 1.1 ]

id

Gets the ID of the table. Read-only.

[ API set: OneNoteApi 1.1 ]

paragraph

Gets the Paragraph object that contains the Table object. Read-only.

[ API set: OneNoteApi 1.1 ]

rowCount

Gets the number of rows in the table.

[ API set: OneNoteApi 1.1 ]

rows

Gets all of the table rows. Read-only.

[ API set: OneNoteApi 1.1 ]

Methods

appendColumn(values)

Adds a column to the end of the table. Values, if specified, are set in the new column. Otherwise the column is empty.

[ API set: OneNoteApi 1.1 ]

appendRow(values)

Adds a row to the end of the table. Values, if specified, are set in the new row. Otherwise the row is empty.

[ API set: OneNoteApi 1.1 ]

clear()

Clears the contents of the table.

[ API set: OneNoteApi 1.1 ]

getCell(rowIndex, cellIndex)

Gets the table cell at a specified row and column.

[ API set: OneNoteApi 1.1 ]

insertColumn(index, values)

Inserts a column at the given index in the table. Values, if specified, are set in the new column. Otherwise the column is empty.

[ API set: OneNoteApi 1.1 ]

insertRow(index, values)

Inserts a row at the given index in the table. Values, if specified, are set in the new row. Otherwise the row is empty.

[ API set: OneNoteApi 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.

setShadingColor(colorCode)

Sets the shading color of all cells in the table. The color code to set the cells to.

[ API set: OneNoteApi 1.1 ]

toJSON()
track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you are using this object across ".sync" calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you needed to have added the object to the tracked object collection when the object was first created.

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call "context.sync()" before the memory release takes effect.

Property Details

borderVisible

Gets or sets whether the borders are visible or not. True if they are visible, false if they are hidden.

[ API set: OneNoteApi 1.1 ]

borderVisible: boolean;

Property Value

boolean

columnCount

Gets the number of columns in the table.

[ API set: OneNoteApi 1.1 ]

readonly columnCount: number;

Property Value

number

id

Gets the ID of the table. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly id: string;

Property Value

string

paragraph

Gets the Paragraph object that contains the Table object. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly paragraph: OneNote.Paragraph;

Property Value

rowCount

Gets the number of rows in the table.

[ API set: OneNoteApi 1.1 ]

readonly rowCount: number;

Property Value

number

rows

Gets all of the table rows. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly rows: OneNote.TableRowCollection;

Property Value

OneNote.TableRowCollection

Method Details

appendColumn(values)

Adds a column to the end of the table. Values, if specified, are set in the new column. Otherwise the column is empty.

[ API set: OneNoteApi 1.1 ]

appendColumn(values?: string[]): void;

Parameters

values
string[]

Optional. Strings to insert in the new column, specified as an array. Must not have more values than rows in the table.

Returns

void

Examples

OneNote.run(function(ctx) {
    var app = ctx.application;
    var outline = app.getActiveOutline();

    // Queue a command to load outline.paragraphs and their types.
    ctx.load(outline, "paragraphs, paragraphs/type");

    // Run the queued commands, and return a promise to indicate task completion.
    return ctx.sync().then(function () {
        var paragraphs = outline.paragraphs;

        // for each table, append a column.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;
                table.appendColumn(["cell0", "cell1"]);
            }
        }
        return ctx.sync();
    })
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

appendRow(values)

Adds a row to the end of the table. Values, if specified, are set in the new row. Otherwise the row is empty.

[ API set: OneNoteApi 1.1 ]

appendRow(values?: string[]): OneNote.TableRow;

Parameters

values
string[]

Optional. Strings to insert in the new row, specified as an array. Must not have more values than columns in the table.

Returns

OneNote.TableRow

Examples

OneNote.run(function(ctx) {
    var app = ctx.application;
    var outline = app.getActiveOutline();

    // Queue a command to load outline.paragraphs and their types.
    ctx.load(outline, "paragraphs, paragraphs/type");

    // Run the queued commands, and return a promise to indicate task completion.
    return ctx.sync().then(function () {
        var paragraphs = outline.paragraphs;

        // for each table, append a column.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;
                var row = table.appendRow(["cell0", "cell1"]);
            }
        }
        return ctx.sync();
    })
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

clear()

Clears the contents of the table.

[ API set: OneNoteApi 1.1 ]

clear(): void;

Returns

void

getCell(rowIndex, cellIndex)

Gets the table cell at a specified row and column.

[ API set: OneNoteApi 1.1 ]

getCell(rowIndex: number, cellIndex: number): OneNote.TableCell;

Parameters

rowIndex
number

The index of the row.

cellIndex
number

The index of the cell in the row.

Returns

Examples

OneNote.run(function(ctx) {
    var app = ctx.application;
    var outline = app.getActiveOutline();

    // Queue a command to load outline.paragraphs and their types.
    ctx.load(outline, "paragraphs, paragraphs/type");

    // Run the queued commands, and return a promise to indicate task completion.
    return ctx.sync().then(function () {
        var paragraphs = outline.paragraphs;

        // for each table, get a cell in the second row and third column.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;
                var cell = table.getCell(2 /*Row Index*/, 3 /*Column Index*/);
            }
        }
        return ctx.sync();
    })
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

insertColumn(index, values)

Inserts a column at the given index in the table. Values, if specified, are set in the new column. Otherwise the column is empty.

[ API set: OneNoteApi 1.1 ]

insertColumn(index: number, values?: string[]): void;

Parameters

index
number

Index where the column will be inserted in the table.

values
string[]

Optional. Strings to insert in the new column, specified as an array. Must not have more values than rows in the table.

Returns

void

Examples

OneNote.run(function(ctx) {
    var app = ctx.application;
    var outline = app.getActiveOutline();

    // Queue a command to load outline.paragraphs and their types.
    ctx.load(outline, "paragraphs, paragraphs/type");

    // Run the queued commands, and return a promise to indicate task completion.
    return ctx.sync().then(function () {
        var paragraphs = outline.paragraphs;

        // for each table, insert a column at index two.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;
                table.insertColumn(2, ["cell0", "cell1"]);
            }
        }
        return ctx.sync();
    })
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

insertRow(index, values)

Inserts a row at the given index in the table. Values, if specified, are set in the new row. Otherwise the row is empty.

[ API set: OneNoteApi 1.1 ]

insertRow(index: number, values?: string[]): OneNote.TableRow;

Parameters

index
number

Index where the row will be inserted in the table.

values
string[]

Optional. Strings to insert in the new row, specified as an array. Must not have more values than columns in the table.

Returns

OneNote.TableRow

Examples

OneNote.run(function(ctx) {
    var app = ctx.application;
    var outline = app.getActiveOutline();

    // Queue a command to load outline.paragraphs and their types.
    ctx.load(outline, "paragraphs, paragraphs/type");

    // Run the queued commands, and return a promise to indicate task completion.
    return ctx.sync().then(function () {
        var paragraphs = outline.paragraphs;

        // for each table, insert a row at index two.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;
                var row = table.insertRow(2, ["cell0", "cell1"]);
            }
        }
        return ctx.sync();
    })
})
.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?: string | string[]): OneNote.Table;

Parameters

option
string | string[]

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

Returns

OneNote.Table

Remarks

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

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

OneNote.run(function(ctx) {
    var app = ctx.application;
    var outline = app.getActiveOutline();

    // Queue a command to load outline.paragraphs and their types.
    ctx.load(outline, "paragraphs/type");

    // Run the queued commands, and return a promise to indicate task completion.
    return ctx.sync().then(function () {
        var paragraphs = outline.paragraphs;

        // For each table, log properties.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;
                ctx.load(table);
                return ctx.sync().then(function() {
                    console.log("Table Id: " + table.id);
                    console.log("Row Count: " + table.rowCount);
                    console.log("Column Count: " + table.columnCount);
                    return ctx.sync();
                });
            }
        }
    });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
OneNote.run(function(ctx) {
    var app = ctx.application;
    var outline = app.getActiveOutline();

    // Queue a command to load outline.paragraphs and their types.
    ctx.load(outline, "paragraphs, paragraphs/type");

    // Run the queued commands, and return a promise to indicate task completion.
    return ctx.sync().then(function () {
        var paragraphs = outline.paragraphs;

        // for each table, log its paragraph id.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;
                ctx.load(table, "paragraph/id, rows/id");
                return ctx.sync().then(function() {
                    console.log("Paragraph Id: " + table.paragraph.id);
                    var rows = table.rows;

                    // for each rows in the table, log row index and id.
                    for (var i = 0; i < rows.items.length; i++) {
                        console.log("Row " + i + " Id: " + rows.items[i].id);
                    }
                    return ctx.sync();
                });
            }
        }
    })
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

setShadingColor(colorCode)

Sets the shading color of all cells in the table. The color code to set the cells to.

[ API set: OneNoteApi 1.1 ]

setShadingColor(colorCode: string): void;

Parameters

colorCode
string

Returns

void

toJSON()

toJSON(): OneNote.Interfaces.TableData;

Returns

OneNote.Interfaces.TableData

track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you are using this object across ".sync" calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you needed to have added the object to the tracked object collection when the object was first created.

track(): OneNote.Table;

Returns

OneNote.Table

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call "context.sync()" before the memory release takes effect.

untrack(): OneNote.Table;

Returns

OneNote.Table