OneNote.TableRow class

Represents a row in a table.

Extends

Remarks

[ API set: OneNoteApi 1.1 ]

Properties

cellCount

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

cells

Gets the cells in the row. Read-only.

context

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

id

Gets the ID of the row. Read-only.

parentTable

Gets the parent table. Read-only.

rowIndex

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

Methods

clear()

Clears the contents of the row.

insertRowAsSibling(insertLocation, values)

Inserts a row before or after the current row.

insertRowAsSibling(insertLocationString, values)

Inserts a row before or after the current row.

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.

setShadingColor(colorCode)

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

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 OneNote.TableRow object is an API object, the toJSON method returns a plain JavaScript object (typed as OneNote.Interfaces.TableRowData) that contains shallow copies of any loaded child properties from the original object.

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.

readonly cellCount: number;

Property Value

number

Remarks

[ API set: OneNoteApi 1.1 ]

cells

Gets the cells in the row. Read-only.

readonly cells: OneNote.TableCellCollection;

Property Value

Remarks

[ API set: OneNoteApi 1.1 ]

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

id

Gets the ID of the row. Read-only.

readonly id: string;

Property Value

string

Remarks

[ API set: OneNoteApi 1.1 ]

parentTable

Gets the parent table. Read-only.

readonly parentTable: OneNote.Table;

Property Value

Remarks

[ API set: OneNoteApi 1.1 ]

rowIndex

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

readonly rowIndex: number;

Property Value

number

Remarks

[ API set: OneNoteApi 1.1 ]

Method Details

clear()

Clears the contents of the row.

clear(): void;

Returns

void

Remarks

[ API set: OneNoteApi 1.1 ]

insertRowAsSibling(insertLocation, values)

Inserts a row before or after the current row.

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

Remarks

[ API set: OneNoteApi 1.1 ]

Examples

await OneNote.run(async (context) => {
    const app = context.application;
    const outline = app.getActiveOutline();
    
    // Queue a command to load outline.paragraphs and their types.
    context.load(outline, "paragraphs, paragraphs/type");
    
    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();
    
    const paragraphs = outline.paragraphs;
    
    // For each table, get table rows.
    for (let i = 0; i < paragraphs.items.length; i++) {
        const paragraph = paragraphs.items[i];
        if (paragraph.type == "Table") {
            const table = paragraph.table;
            
            // Queue a command to load table.rows.
            context.load(table, "rows");
            
            // Run the queued commands.
            await context.sync();

            const rows = table.rows;
            rows.items[1].insertRowAsSibling("Before", ["cell0", "cell1"]);
            await context.sync();
        }
    }
});

insertRowAsSibling(insertLocationString, values)

Inserts a row before or after the current row.

insertRowAsSibling(insertLocationString: "Before" | "After", values?: string[]): OneNote.TableRow;

Parameters

insertLocationString

"Before" | "After"

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

Remarks

[ API set: OneNoteApi 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(options?: OneNote.Interfaces.TableRowLoadOptions): OneNote.TableRow;

Parameters

options
OneNote.Interfaces.TableRowLoadOptions

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[]): OneNote.TableRow;

Parameters

propertyNames

string | string[]

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

Returns

Examples

await OneNote.run(async (context) => {
    const app = context.application;
    const outline = app.getActiveOutline();
    
    // Queue a command to load outline.paragraphs and their types.
    context.load(outline, "paragraphs, paragraphs/type");
    
    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();
    
    const paragraphs = outline.paragraphs;
    
    // For each table, get table rows.
    for (let i = 0; i < paragraphs.items.length; i++) {
        const paragraph = paragraphs.items[i];
        if (paragraph.type == "Table") {
            const table = paragraph.table;
            
            // Queue a command to load table.rows.
            context.load(table, "rows");
            await context.sync();

            const rows = table.rows;
            
            // For each table row, log cell count and row index.
            for (let 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);
            }
            await context.sync();
        }
    }
});

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;
        }): OneNote.TableRow;

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

setShadingColor(colorCode)

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

setShadingColor(colorCode: string): void;

Parameters

colorCode

string

Returns

void

Remarks

[ API set: OneNoteApi 1.1 ]

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 OneNote.TableRow object is an API object, the toJSON method returns a plain JavaScript object (typed as OneNote.Interfaces.TableRowData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): OneNote.Interfaces.TableRowData;

Returns

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

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