OneNote.TableRow class

Represents a row in a table.

[ API set: OneNoteApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

cellCount

Gets the number of cells in the row. Read-only.

[ API set: OneNoteApi 1.1 ]

cells

Gets the cells in the row. Read-only.

[ API set: OneNoteApi 1.1 ]

id

Gets the ID of the row. Read-only.

[ API set: OneNoteApi 1.1 ]

parentTable

Gets the parent table. Read-only.

[ API set: OneNoteApi 1.1 ]

rowIndex

Gets the index of the row in its parent table. Read-only.

[ API set: OneNoteApi 1.1 ]

Methods

clear()

Clears the contents of the row.

[ API set: OneNoteApi 1.1 ]

insertRowAsSibling(insertLocation, values)

Inserts a row before or after the current row.

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

cellCount

Gets the number of cells in the row. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly cellCount: number;
Property Value
number

cells

Gets the cells in the row. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly cells: OneNote.TableCellCollection;
Property Value

id

Gets the ID of the row. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly id: string;
Property Value
string

parentTable

Gets the parent table. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly parentTable: OneNote.Table;
Property Value
OneNote.Table

rowIndex

Gets the index of the row in its parent table. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly rowIndex: number;
Property Value
number

Method Details

clear()

Clears the contents of the row.

[ API set: OneNoteApi 1.1 ]

clear(): void;
Returns
void

insertRowAsSibling(insertLocation, values)

Inserts a row before or after the current row.

[ API set: OneNoteApi 1.1 ]

insertRowAsSibling(insertLocation: OneNote.InsertLocation, values?: string[]): OneNote.TableRow;
Parameters
insertLocation
OneNote.InsertLocation

Where the new rows should be inserted relative to the current row.

values
string[]

Strings to insert in the new row, specified as an array. Must not have more cells than in the current row. Optional.

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, get table rows.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;

                // Queue a command to load table.rows.
                ctx.load(table, "rows");

                // Run the queued commands
                return ctx.sync().then(function() {
                    var rows = table.rows;
                    rows.items[1].insertRowAsSibling("Before", ["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.TableRow;
Parameters
option
string | string[]

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

Returns
OneNote.TableRow
Remarks

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

load(option?: { select?: string; expand?: string; }): OneNote.TableRow - 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.TableRow - 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, 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 table rows.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;

                // Queue a command to load table.rows.
                ctx.load(table, "rows");
                return ctx.sync().then(function() {
                    var rows = table.rows;

                    // for each table row, log cell count and row index.
                    for (var i = 0; i < rows.items.length; i++) {
                        console.log("Row " + i + " Id: " + rows.items[i].id);
                        console.log("Row " + i + " Cell Count: " + rows.items[i].cellCount);
                        console.log("Row " + i + " Row Index: " + rows.items[i].rowIndex);
                    }
                    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, get table rows.
        for (var i = 0; i < paragraphs.items.length; i++) {
            var paragraph = paragraphs.items[i];
            if (paragraph.type == "Table") {
                var table = paragraph.table;

                // Queue a command to load parentTable and cells of each row in the table.
                ctx.load(table, "rows/parentTable, rows/cells");
                return ctx.sync().then(function() {
                    var rows = table.rows;

                    // for each row, log parentTable and cells
                    for (var i = 0; i < rows.items.length; i++) {
                        console.log("Row " + i + " Parent Table Id: " + rows.items[i].parentTable.id);
                        var cells = rows.items[i].cells;
                        for (var j = 0 ; j < cells.items.length; j++) {
                            console.log("Row " + i + " Cell " + j + " Id: " + cells.items[j].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 row. 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.TableRowData;
Returns
OneNote.Interfaces.TableRowData

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.TableRow;
Returns
OneNote.TableRow

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.TableRow;
Returns
OneNote.TableRow