OneNote.TableCell class
Represents a cell in a OneNote table.
- Extends
Remarks
Properties
cell |
Gets the index of the cell in its 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 cell. Read-only. |
paragraphs | Gets the collection of Paragraph objects in the TableCell. Read-only. |
parent |
Gets the parent row of the cell. Read-only. |
row |
Gets the index of the cell's row in the table. Read-only. |
shading |
Gets and sets the shading color of the cell |
Methods
append |
Adds the specified HTML to the bottom of the TableCell. |
append |
Adds the specified image to table cell. |
append |
Adds the specified text to table cell. |
append |
Adds a table with the specified number of rows and columns to table cell. |
clear() | Clears the contents of the cell. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
set(properties, options) | Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type. |
set(properties) | Sets multiple properties on the object at the same time, based on an existing loaded object. |
toJSON() | Overrides the JavaScript |
track() | Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for |
untrack() | Release the memory associated with this object, if it has previously been tracked. This call is shorthand for |
Property Details
cellIndex
Gets the index of the cell in its row. Read-only.
readonly cellIndex: number;
Property Value
number
Remarks
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 cell. Read-only.
readonly id: string;
Property Value
string
Remarks
paragraphs
Gets the collection of Paragraph objects in the TableCell. Read-only.
readonly paragraphs: OneNote.ParagraphCollection;
Property Value
Remarks
parentRow
Gets the parent row of the cell. Read-only.
readonly parentRow: OneNote.TableRow;
Property Value
Remarks
rowIndex
Gets the index of the cell's row in the table. Read-only.
readonly rowIndex: number;
Property Value
number
Remarks
shadingColor
Gets and sets the shading color of the cell
shadingColor: string;
Property Value
string
Remarks
Method Details
appendHtml(html)
Adds the specified HTML to the bottom of the TableCell.
appendHtml(html: string): void;
Parameters
- html
-
string
The HTML string to append. See Supported HTML for the OneNote add-ins JavaScript API.
Returns
void
Remarks
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 a table cell at row one and column two and add "Hello".
for (let i = 0; i < paragraphs.items.length; i++) {
const paragraph = paragraphs.items[i];
if (paragraph.type == "Table") {
const table = paragraph.table;
const cell = table.getCell(1 /*Row Index*/, 2 /*Column Index*/);
cell.appendHtml("<p>Hello</p>");
}
}
await context.sync();
});
appendImage(base64EncodedImage, width, height)
Adds the specified image to table cell.
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
Remarks
appendRichText(paragraphText)
Adds the specified text to table cell.
appendRichText(paragraphText: string): OneNote.RichText;
Parameters
- paragraphText
-
string
HTML string to append.
Returns
Remarks
Examples
await OneNote.run(async (context) => {
const app = context.application;
const outline = app.getActiveOutline();
const appendedRichText = null;
// 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 a table cell at row one and column two and add "Hello".
for (let i = 0; i < paragraphs.items.length; i++) {
const paragraph = paragraphs.items[i];
if (paragraph.type == "Table") {
const table = paragraph.table;
const cell = table.getCell(1 /*Row Index*/, 2 /*Column Index*/);
appendedRichText = cell.appendRichText("Hello");
}
}
await context.sync();
});
appendTable(rowCount, columnCount, values)
Adds a table with the specified number of rows and columns to table cell.
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
Remarks
clear()
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.TableCellLoadOptions): OneNote.TableCell;
Parameters
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.TableCell;
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 a table cell at row one and column two.
for (let i = 0; i < paragraphs.items.length; i++) {
const paragraph = paragraphs.items[i];
if (paragraph.type == "Table") {
const table = paragraph.table;
const cell = table.getCell(1 /*Row Index*/, 2 /*Column Index*/);
// Queue a command to load the table cell.
context.load(cell);
await context.sync();
console.log("Cell Id: " + cell.id);
console.log("Cell Index: " + cell.cellIndex);
console.log("Cell's Row Index: " + cell.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.TableCell;
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
set(properties, options)
Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.
set(properties: Interfaces.TableCellUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- OneNote.Interfaces.TableCellUpdateData
A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.
- options
- OfficeExtension.UpdateOptions
Provides an option to suppress errors if the properties object tries to set any read-only properties.
Returns
void
set(properties)
Sets multiple properties on the object at the same time, based on an existing loaded object.
set(properties: OneNote.TableCell): void;
Parameters
- properties
- OneNote.TableCell
Returns
void
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.TableCell object is an API object, the toJSON
method returns a plain JavaScript object (typed as OneNote.Interfaces.TableCellData
) that contains shallow copies of any loaded child properties from the original object.
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
Office Add-ins