OneNote.Application class
Represents the top-level object that contains all globally addressable OneNote objects such as notebooks, the active notebook, and the active section.
- Extends
Remarks
Properties
context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
notebooks | Gets the collection of notebooks that are open in the OneNote application instance. In OneNote Online, only one notebook at a time is open in the application instance. Read-only. |
Methods
get |
Gets the active notebook if one exists. If no notebook is active, throws ItemNotFound. |
get |
Gets the active notebook if one exists. If no notebook is active, returns null. |
get |
Gets the active outline if one exists, If no outline is active, throws ItemNotFound. |
get |
Gets the active outline if one exists, otherwise returns null. |
get |
Gets the active page if one exists. If no page is active, throws ItemNotFound. |
get |
Gets the active page if one exists. If no page is active, returns null. |
get |
Gets the active Paragraph if one exists, If no Paragraph is active, throws ItemNotFound. |
get |
Gets the active Paragraph if one exists, otherwise returns null. |
get |
Gets the active section if one exists. If no section is active, throws ItemNotFound. |
get |
Gets the active section if one exists. If no section is active, returns null. |
get |
Gets the currently selected ink strokes. |
get |
|
insert |
|
is |
|
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 |
navigate |
Opens the specified page in the application instance. |
navigate |
Gets the specified page, and opens it in the application instance. Navigation may still not be carried out when no fails. Caller should validate the returned page if so desired. |
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 |
Property Details
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
notebooks
Gets the collection of notebooks that are open in the OneNote application instance. In OneNote Online, only one notebook at a time is open in the application instance. Read-only.
readonly notebooks: OneNote.NotebookCollection;
Property Value
Remarks
Method Details
getActiveNotebook()
Gets the active notebook if one exists. If no notebook is active, throws ItemNotFound.
getActiveNotebook(): OneNote.Notebook;
Returns
Remarks
Examples
await OneNote.run(async (context) => {
// Get the active notebook.
const notebook = context.application.getActiveNotebook();
// Queue a command to load the notebook.
// For best performance, request specific properties.
notebook.load('id,name');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync();
// Show some properties.
console.log("Notebook name: " + notebook.name);
console.log("Notebook ID: " + notebook.id);
});
getActiveNotebookOrNull()
Gets the active notebook if one exists. If no notebook is active, returns null.
getActiveNotebookOrNull(): OneNote.Notebook;
Returns
Remarks
Examples
await OneNote.run(async (context) => {
// Get the active notebook.
const notebook = context.application.getActiveNotebookOrNull();
// Queue a command to load the notebook.
// For best performance, request specific properties.
notebook.load('id,name');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync();
// Check if active notebook is set.
if (!notebook.isNullObject) {
console.log("Notebook name: " + notebook.name);
console.log("Notebook ID: " + notebook.id);
}
});
getActiveOutline()
Gets the active outline if one exists, If no outline is active, throws ItemNotFound.
getActiveOutline(): OneNote.Outline;
Returns
Remarks
Examples
await OneNote.run(async (context) => {
// get active outline.
const outline = context.application.getActiveOutline();
// Queue a command to load the id of the outline.
outline.load('id');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync();
// Show some properties.
console.log("outline id: " + outline.id);
});
getActiveOutlineOrNull()
Gets the active outline if one exists, otherwise returns null.
getActiveOutlineOrNull(): OneNote.Outline;
Returns
Remarks
Examples
await OneNote.run(async (context) => {
// get active outline.
const outline = context.application.getActiveOutlineOrNull();
// Queue a command to load the id of the outline.
outline.load('id');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync();
if (!outline.isNullObject) {
console.log("outline id: " + outline.id);
}
});
getActivePage()
Gets the active page if one exists. If no page is active, throws ItemNotFound.
getActivePage(): OneNote.Page;
Returns
Remarks
Examples
await OneNote.run(async (context) => {
// Get the active page.
const page = context.application.getActivePage();
// Queue a command to load the page.
// For best performance, request specific properties.
page.load('id,title');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync();
// Show some properties.
console.log("Page title: " + page.title);
console.log("Page ID: " + page.id);
});
getActivePageOrNull()
Gets the active page if one exists. If no page is active, returns null.
getActivePageOrNull(): OneNote.Page;
Returns
Remarks
Examples
await OneNote.run(async (context) => {
// Get the active page.
const page = context.application.getActivePageOrNull();
// Queue a command to load the page.
// For best performance, request specific properties.
page.load('id,title');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync();
if (!page.isNullObject) {
// Show some properties.
console.log("Page title: " + page.title);
console.log("Page ID: " + page.id);
}
});
getActiveParagraph()
Gets the active Paragraph if one exists, If no Paragraph is active, throws ItemNotFound.
getActiveParagraph(): OneNote.Paragraph;
Returns
Remarks
getActiveParagraphOrNull()
Gets the active Paragraph if one exists, otherwise returns null.
getActiveParagraphOrNull(): OneNote.Paragraph;
Returns
Remarks
getActiveSection()
Gets the active section if one exists. If no section is active, throws ItemNotFound.
getActiveSection(): OneNote.Section;
Returns
Remarks
Examples
await OneNote.run(async (context) => {
// Get the active section.
const section = context.application.getActiveSection();
// Queue a command to load the section.
// For best performance, request specific properties.
section.load('id,name');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync();
// Show some properties.
console.log("Section name: " + section.name);
console.log("Section ID: " + section.id);
});
getActiveSectionOrNull()
Gets the active section if one exists. If no section is active, returns null.
getActiveSectionOrNull(): OneNote.Section;
Returns
Remarks
Examples
await OneNote.run(async (context) => {
// Get the active section.
const section = context.application.getActiveSectionOrNull();
// Queue a command to load the section.
// For best performance, request specific properties.
section.load('id,name');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync();
if (!section.isNullObject) {
// Show some properties.
console.log("Section name: " + section.name);
console.log("Section ID: " + section.id);
}
});
getSelectedInkStrokes()
Gets the currently selected ink strokes.
getSelectedInkStrokes(): OneNote.InkStrokeCollection;
Returns
Remarks
getWindowSize()
getWindowSize(): OfficeExtension.ClientResult<number[]>;
Returns
OfficeExtension.ClientResult<number[]>
insertHtmlAtCurrentPosition(html)
insertHtmlAtCurrentPosition(html: string): void;
Parameters
- html
-
string
Returns
void
isViewingDeletedNotes()
isViewingDeletedNotes(): OfficeExtension.ClientResult<boolean>;
Returns
OfficeExtension.ClientResult<boolean>
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.ApplicationLoadOptions): OneNote.Application;
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.Application;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
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.Application;
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
navigateToPage(page)
Opens the specified page in the application instance.
navigateToPage(page: OneNote.Page): void;
Parameters
- page
- OneNote.Page
The page to open.
Returns
void
Remarks
Examples
await OneNote.run(async (context) => {
// Get the pages in the current section.
const pages = context.application.getActiveSection().pages;
// Queue a command to load the pages.
// For best performance, request specific properties.
pages.load('id');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync()
// This example loads the first page in the section.
const page = pages.items[0];
// Open the page in the application.
context.application.navigateToPage(page);
// Run the queued command.
await context.sync();
});
navigateToPageWithClientUrl(url)
Gets the specified page, and opens it in the application instance. Navigation may still not be carried out when no fails. Caller should validate the returned page if so desired.
navigateToPageWithClientUrl(url: string): OneNote.Page;
Parameters
- url
-
string
The client url of the page to open.
Returns
Remarks
Examples
await OneNote.run(async (context) => {
// Get the pages in the current section.
const pages = context.application.getActiveSection().pages;
// Queue a command to load the pages.
// For best performance, request specific properties.
pages.load('clientUrl');
// Run the queued commands, and return a promise to indicate task completion.
await context.sync()
// This example loads the first page in the section.
const page = pages.items[0];
// Open the page in the application.
context.application.navigateToPageWithClientUrl(page.clientUrl);
// Run the queued command.
await context.sync();
});
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.ApplicationUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- OneNote.Interfaces.ApplicationUpdateData
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.Application): void;
Parameters
- properties
- OneNote.Application
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.Application object is an API object, the toJSON
method returns a plain JavaScript object (typed as OneNote.Interfaces.ApplicationData
) that contains shallow copies of any loaded child properties from the original object.
toJSON(): OneNote.Interfaces.ApplicationData;
Returns
Office Add-ins