OneNote.TableCell class

Represents a cell in a OneNote table.

[ API set: OneNoteApi 1.1 ]

Extends
OfficeExtension.ClientObject

Properties

cellIndex

Gets the index of the cell in its row. Read-only.

[ API set: OneNoteApi 1.1 ]

id

Gets the ID of the cell. Read-only.

[ API set: OneNoteApi 1.1 ]

paragraphs

Gets the collection of Paragraph objects in the TableCell. Read-only.

[ API set: OneNoteApi 1.1 ]

parentRow

Gets the parent row of the cell. Read-only.

[ API set: OneNoteApi 1.1 ]

rowIndex

Gets the index of the cell's row in the table. Read-only.

[ API set: OneNoteApi 1.1 ]

shadingColor

Gets and sets the shading color of the cell

[ API set: OneNoteApi 1.1 ]

Methods

appendHtml(html)

Adds the specified HTML to the bottom of the TableCell.

[ API set: OneNoteApi 1.1 ]

appendImage(base64EncodedImage, width, height)

Adds the specified image to table cell.

[ API set: OneNoteApi 1.1 ]

appendRichText(paragraphText)

Adds the specified text to table cell.

[ API set: OneNoteApi 1.1 ]

appendTable(rowCount, columnCount, values)

Adds a table with the specified number of rows and columns to table cell.

[ API set: OneNoteApi 1.1 ]

clear()

Clears the contents of the cell.

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

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

cellIndex

Gets the index of the cell in its row. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly cellIndex: number;
Property Value
number

id

Gets the ID of the cell. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly id: string;
Property Value
string

paragraphs

Gets the collection of Paragraph objects in the TableCell. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly paragraphs: OneNote.ParagraphCollection;
Property Value

parentRow

Gets the parent row of the cell. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly parentRow: OneNote.TableRow;
Property Value
OneNote.TableRow

rowIndex

Gets the index of the cell's row in the table. Read-only.

[ API set: OneNoteApi 1.1 ]

readonly rowIndex: number;
Property Value
number

shadingColor

Gets and sets the shading color of the cell

[ API set: OneNoteApi 1.1 ]

shadingColor: string;
Property Value
string

Method Details

appendHtml(html)

Adds the specified HTML to the bottom of the TableCell.

[ API set: OneNoteApi 1.1 ]

appendHtml(html: string): void;
Parameters
html
string

The HTML string to append. See Supported HTML for the OneNote add-ins JavaScript API.

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, get a table cell at row one and column two and add "Hello".
        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(1 /*Row Index*/, 2 /*Column Index*/);
                cell.appendHtml("<p>Hello</p>");
            }
        }
        return ctx.sync();
    })
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

appendImage(base64EncodedImage, width, height)

Adds the specified image to table cell.

[ API set: OneNoteApi 1.1 ]

appendImage(base64EncodedImage: string, width: number, height: number): OneNote.Image;
Parameters
base64EncodedImage
string

HTML string to append.

width
number

Optional. Width in the unit of Points. The default value is null and image width will be respected.

height
number

Optional. Height in the unit of Points. The default value is null and image height will be respected.

Returns

appendRichText(paragraphText)

Adds the specified text to table cell.

[ API set: OneNoteApi 1.1 ]

appendRichText(paragraphText: string): OneNote.RichText;
Parameters
paragraphText
string

HTML string to append.

Returns

Examples

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

    // 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 table cell at row one and column two and add "Hello".
        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(1 /*Row Index*/, 2 /*Column Index*/);
                appendedRichText = cell.appendRichText("Hello");
            }
        }
        return ctx.sync();
    })
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

appendTable(rowCount, columnCount, values)

Adds a table with the specified number of rows and columns to table cell.

[ API set: OneNoteApi 1.1 ]

appendTable(rowCount: number, columnCount: number, values?: string[][]): OneNote.Table;
Parameters
rowCount
number

Required. The number of rows in the table.

columnCount
number

Required. The number of columns in the table.

values
string[][]

Optional 2D array. Cells are filled if the corresponding strings are specified in the array.

Returns
OneNote.Table

clear()

Clears the contents of the cell.

[ API set: OneNoteApi 1.1 ]

clear(): void;
Returns
void

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.TableCell;
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; }): OneNote.TableCell - 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.TableCell - 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 a table cell at row one and column two.
        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(1 /*Row Index*/, 2 /*Column Index*/);

                // Queue a command to load the table cell.
                ctx.load(cell);
                ctx.sync().then(function() {
                    console.log("Cell Id: " + cell.id);
                    console.log("Cell Index: " + cell.cellIndex);
                    console.log("Cell's Row Index: " + cell.rowIndex);
                });
            }
        }
        return ctx.sync();
    })
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
ParentTable, ParentRow, Paragraphs
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 table cell at row one and column two.
        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(1 /*Row Index*/, 2 /*Column Index*/);

                // Queue a command to load parentTable, parentRow and paragraphs of the table cell.
                ctx.load(cell, "parentTable, parentRow, paragraphs");

                ctx.sync().then(function() {
                    console.log("Parent Table Id: " + cell.parentTable.id);
                    console.log("Parent Row Id: " + cell.parentRow.id);
                    var paragraphs = cell.paragraphs;

                    for (var i = 0; i < paragraphs.items.length; i++) {
                        console.log("Paragraph Id: " + paragraphs.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));
    }
});

toJSON()

toJSON(): OneNote.Interfaces.TableCellData;
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.TableCell;
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.TableCell;
Returns