OneNote.Application class

表示包含所有全局可寻址的 OneNote 对象的顶级对象,例如笔记本、活动笔记本和活动分区。

Extends

注解

[ API 集:OneNoteApi 1.1 ]

属性

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

notebooks

获取 OneNote 应用程序实例中打开的笔记本集合。 在 OneNote Online 的应用程序实例中,笔记本一次仅能打开一个。 只读。

方法

getActiveNotebook()

如果活动笔记本存在,则对其获取。 如果没有处于活动状态的部分,则引发 ItemNotFound。

getActiveNotebookOrNull()

如果活动笔记本存在,则对其获取。 如果没有处于活动状态的部分,则返回 null。

getActiveOutline()

如果活动边框存在,则对其获取,如果没有处于活动状态的边框,则引发 ItemNotFound。

getActiveOutlineOrNull()

如果活动边框存在,则对其获取,否则,返回 null。

getActivePage()

如果活动页面存在,则对其获取。 如果没有处于活动状态的页面,则引发 ItemNotFound。

getActivePageOrNull()

如果活动页面存在,则对其获取。 如果没有处于活动状态的页面,则返回 null。

getActiveParagraph()

获取活动段落(如果存在),如果没有 Paragraph 处于活动状态,则引发 ItemNotFound。

getActiveParagraphOrNull()

获取活动段落(如果存在),否则返回 null。

getActiveSection()

如果活动分区存在,则对其获取。 如果没有处于活动状态的分区,则引发 ItemNotFound。

getActiveSectionOrNull()

如果活动分区存在,则对其获取。 如果没有处于活动状态的分区,则返回 null。

getSelectedInkStrokes()

获取当前选定的墨迹笔划。

getWindowSize()
insertHtmlAtCurrentPosition(html)
isViewingDeletedNotes()
load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

navigateToPage(page)

打开应用程序实例中指定的页面。

navigateToPageWithClientUrl(url)

获取特定页面,并在应用程序实例中将其打开。 当未失败时,导航可能仍无法执行。 如果需要,调用方应验证返回的页面。

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。

set(properties)

基于现有的已加载对象,同时对对象设置多个属性。

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始 OneNote.Application 对象是 API 对象,toJSON该方法返回一个纯 JavaScript 对象, (类型为 OneNote.Interfaces.ApplicationData) ,该对象包含从原始对象加载的任何子属性的浅表副本。

属性详细信息

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

notebooks

获取 OneNote 应用程序实例中打开的笔记本集合。 在 OneNote Online 的应用程序实例中,笔记本一次仅能打开一个。 只读。

readonly notebooks: OneNote.NotebookCollection;

属性值

注解

[ API 集:OneNoteApi 1.1 ]

方法详细信息

getActiveNotebook()

如果活动笔记本存在,则对其获取。 如果没有处于活动状态的部分,则引发 ItemNotFound。

getActiveNotebook(): OneNote.Notebook;

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

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()

如果活动笔记本存在,则对其获取。 如果没有处于活动状态的部分,则返回 null。

getActiveNotebookOrNull(): OneNote.Notebook;

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

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()

如果活动边框存在,则对其获取,如果没有处于活动状态的边框,则引发 ItemNotFound。

getActiveOutline(): OneNote.Outline;

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

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()

如果活动边框存在,则对其获取,否则,返回 null。

getActiveOutlineOrNull(): OneNote.Outline;

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

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()

如果活动页面存在,则对其获取。 如果没有处于活动状态的页面,则引发 ItemNotFound。

getActivePage(): OneNote.Page;

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

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()

如果活动页面存在,则对其获取。 如果没有处于活动状态的页面,则返回 null。

getActivePageOrNull(): OneNote.Page;

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

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()

获取活动段落(如果存在),如果没有 Paragraph 处于活动状态,则引发 ItemNotFound。

getActiveParagraph(): OneNote.Paragraph;

返回

注解

[ API 集:OneNoteApi 1.1 ]

getActiveParagraphOrNull()

获取活动段落(如果存在),否则返回 null。

getActiveParagraphOrNull(): OneNote.Paragraph;

返回

注解

[ API 集:OneNoteApi 1.1 ]

getActiveSection()

如果活动分区存在,则对其获取。 如果没有处于活动状态的分区,则引发 ItemNotFound。

getActiveSection(): OneNote.Section;

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

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()

如果活动分区存在,则对其获取。 如果没有处于活动状态的分区,则返回 null。

getActiveSectionOrNull(): OneNote.Section;

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

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()

获取当前选定的墨迹笔划。

getSelectedInkStrokes(): OneNote.InkStrokeCollection;

返回

注解

[ API 集:OneNoteApi 1.9 ]

getWindowSize()

getWindowSize(): OfficeExtension.ClientResult<number[]>;

返回

insertHtmlAtCurrentPosition(html)

insertHtmlAtCurrentPosition(html: string): void;

参数

html

string

返回

void

isViewingDeletedNotes()

isViewingDeletedNotes(): OfficeExtension.ClientResult<boolean>;

返回

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: OneNote.Interfaces.ApplicationLoadOptions): OneNote.Application;

参数

options
OneNote.Interfaces.ApplicationLoadOptions

提供要加载对象的属性的选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames?: string | string[]): OneNote.Application;

参数

propertyNames

string | string[]

逗号分隔的字符串或指定要加载的属性的字符串数组。

返回

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): OneNote.Application;

参数

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。

返回

navigateToPage(page)

打开应用程序实例中指定的页面。

navigateToPage(page: OneNote.Page): void;

参数

page
OneNote.Page

要打开的页面。

返回

void

注解

[ API 集:OneNoteApi 1.1 ]

示例

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)

获取特定页面,并在应用程序实例中将其打开。 当未失败时,导航可能仍无法执行。 如果需要,调用方应验证返回的页面。

navigateToPageWithClientUrl(url: string): OneNote.Page;

参数

url

string

要打开页面的客户端 url。

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

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)

同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。

set(properties: Interfaces.ApplicationUpdateData, options?: OfficeExtension.UpdateOptions): void;

参数

properties
OneNote.Interfaces.ApplicationUpdateData

一个 JavaScript 对象,其属性按同构方式构造为调用方法的对象的属性。

options
OfficeExtension.UpdateOptions

提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止显示错误。

返回

void

set(properties)

基于现有的已加载对象,同时对对象设置多个属性。

set(properties: OneNote.Application): void;

参数

properties
OneNote.Application

返回

void

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始 OneNote.Application 对象是 API 对象,toJSON该方法返回一个纯 JavaScript 对象, (类型为 OneNote.Interfaces.ApplicationData) ,该对象包含从原始对象加载的任何子属性的浅表副本。

toJSON(): OneNote.Interfaces.ApplicationData;

返回