OneNote.Page class

表示一个 OneNote 页面。

Extends

注解

[ API 集:OneNoteApi 1.1 ]

属性

classNotebookPageSource

获取页面的 ClassNotebookPageSource。

clientUrl

页面的客户端 URL。 只读

contents

页面上 PageContent 对象的集合。 只读

context

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

id

获取页面的 ID。 只读。

inkAnalysisOrNull

页面上墨迹的文本解释。 如果没有墨迹分析信息,则返回 null。

pageLevel

获取或设置页面的缩进级别。

parentSection

获取包含页面的分区。 只读。

title

获取或设置页面的标题。

webUrl

页面的 Web URL。 只读

方法

addOutline(left, top, html)

添加 Outline 至指定位置的页面。

analyzePage()

返回一个 json 字符串,其中包含节点 ID 和 html 格式的内容。

applyTranslation(translatedContent)

插入包含已翻译内容的新页面。

copyToSection(destinationSection)

将此页复制到指定的分区中。

copyToSectionAndSetClassNotebookPageSource(destinationSection)

将此页复制到指定的节并设置 ClassNotebookPageSource。

getRestApiId()

获取 REST API ID。

hasTitleContent()

页面是否具有内容标题。

insertPageAsSibling(location, title)

在当前分区之前或之后插入一个新的页面。

insertPageAsSibling(locationString, title)

在当前分区之前或之后插入一个新的页面。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

set(properties, options)

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

set(properties)

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

toJSON()

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

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 的 context.trackedObjects.add(thisObject)简写。 如果跨 .sync 调用和在“.run”批处理的顺序执行之外使用此对象,并在对对象设置属性或调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪的对象集合。

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 的 context.trackedObjects.remove(thisObject)简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存释放生效之前,需要调用 。context.sync()

属性详细信息

classNotebookPageSource

获取页面的 ClassNotebookPageSource。

readonly classNotebookPageSource: string;

属性值

string

注解

[ API 集:OneNoteApi 1.1 ]

clientUrl

页面的客户端 URL。 只读

readonly clientUrl: string;

属性值

string

注解

[ API 集:OneNoteApi 1.1 ]

contents

页面上 PageContent 对象的集合。 只读

readonly contents: OneNote.PageContentCollection;

属性值

注解

[ API 集:OneNoteApi 1.1 ]

context

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

context: RequestContext;

属性值

id

获取页面的 ID。 只读。

readonly id: string;

属性值

string

注解

[ API 集:OneNoteApi 1.1 ]

inkAnalysisOrNull

页面上墨迹的文本解释。 如果没有墨迹分析信息,则返回 null。

readonly inkAnalysisOrNull: OneNote.InkAnalysis;

属性值

注解

[ API 集:OneNoteApi 1.1 ]

pageLevel

获取或设置页面的缩进级别。

pageLevel: number;

属性值

number

注解

[ API 集:OneNoteApi 1.1 ]

parentSection

获取包含页面的分区。 只读。

readonly parentSection: OneNote.Section;

属性值

注解

[ API 集:OneNoteApi 1.1 ]

title

获取或设置页面的标题。

title: string;

属性值

string

注解

[ API 集:OneNoteApi 1.1 ]

webUrl

页面的 Web URL。 只读

readonly webUrl: string;

属性值

string

注解

[ API 集:OneNoteApi 1.1 ]

方法详细信息

addOutline(left, top, html)

添加 Outline 至指定位置的页面。

addOutline(left: number, top: number, html: string): OneNote.Outline;

参数

left

number

顶部的左边位置,Outline 的左角。

top

number

顶部的顶层位置,Outline 的左角。

html

string

描述边框的可视化演示文稿的 HTML 字符串。 请参阅 OneNote 加载项 JavaScript API 支持的 HTML

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

await OneNote.run(async (context) => {

    // Gets the active page.
    const page = context.application.getActivePage();

    // Queue a command to add an outline with given html.
    const outline = page.addOutline(200, 200,
"<p>Images and a table below:</p> \
 <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\"> \
 <img src=\"http://imagenes.es.sftcdn.net/es/scrn/6653000/6653659/microsoft-onenote-2013-01-535x535.png\"> \
 <table> \
   <tr> \
     <td>Jill</td> \
     <td>Smith</td> \
     <td>50</td> \
   </tr> \
   <tr> \
     <td>Eve</td> \
     <td>Jackson</td> \
     <td>94</td> \
   </tr> \
 </table>"     
        );

    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();
});

analyzePage()

返回一个 json 字符串,其中包含节点 ID 和 html 格式的内容。

analyzePage(): OfficeExtension.ClientResult<string>;

返回

注解

[ API 集:OneNoteApi 1.1 ]

applyTranslation(translatedContent)

插入包含已翻译内容的新页面。

applyTranslation(translatedContent: string): void;

参数

translatedContent

string

页面的已翻译内容

返回

void

注解

[ API 集:OneNoteApi 1.1 ]

copyToSection(destinationSection)

将此页复制到指定的分区中。

copyToSection(destinationSection: OneNote.Section): OneNote.Page;

参数

destinationSection
OneNote.Section

要将此页复制到的分区。

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

await OneNote.run(async (context) => {
    const app = context.application;
    
    // Gets the active notebook.
    const notebook = app.getActiveNotebook();
    
    // Gets the active page.
    const page = app.getActivePage();
    
    // Queue a command to load sections under the notebook.
    notebook.load('sections');
    
    let newPage;
    
    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();

    const section = notebook.sections.items[0];
    
    // Copy page to the section.
    newPage = page.copyToSection(section);
    newPage.load('id');
    await context.sync();
    
    console.log(newPage.id);
});

copyToSectionAndSetClassNotebookPageSource(destinationSection)

将此页复制到指定的节并设置 ClassNotebookPageSource。

copyToSectionAndSetClassNotebookPageSource(destinationSection: OneNote.Section): OneNote.Page;

参数

destinationSection
OneNote.Section

返回

注解

[ API 集:OneNoteApi 1.1 ]

getRestApiId()

获取 REST API ID。

getRestApiId(): OfficeExtension.ClientResult<string>;

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

await OneNote.run(async (context) => {
    // Get the current page.
    const page = context.application.getActivePage();
    const restApiId = page.getRestApiId();

    await context.sync();
    console.log("The REST API ID is " + restApiId.value);
    // Note that the REST API ID isn't all you need to interact with the OneNote REST API.
    // This is only required for SharePoint notebooks. baseUrl will be null for OneDrive notebooks.
    // For SharePoint notebooks, the notebook baseUrl should be used to talk to the OneNote REST API
    // according to the OneNote Development Blog.
    // https://learn.microsoft.com/archive/blogs/onenotedev/and-sharepoint-makes-three
});

hasTitleContent()

页面是否具有内容标题。

hasTitleContent(): OfficeExtension.ClientResult<boolean>;

返回

注解

[ API 集:OneNoteApi 1.1 ]

insertPageAsSibling(location, title)

在当前分区之前或之后插入一个新的页面。

insertPageAsSibling(location: OneNote.InsertLocation, title: string): OneNote.Page;

参数

location
OneNote.InsertLocation

相对于当前页面的新页面的位置。

title

string

新页面的标题。

返回

注解

[ API 集:OneNoteApi 1.1 ]

insertPageAsSibling(locationString, title)

在当前分区之前或之后插入一个新的页面。

insertPageAsSibling(locationString: "Before" | "After", title: string): OneNote.Page;

参数

locationString

"Before" | "After"

相对于当前页面的新页面的位置。

title

string

新页面的标题。

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

await OneNote.run(async (context) => {

    // Gets the active page.
    const activePage = context.application.getActivePage();

    // Queue a command to add a new page after the active page.
    const newPage = activePage.insertPageAsSibling("After", "Next Page");

    // Queue a command to load the newPage to access its data.
    context.load(newPage);

    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();
    console.log("page is created with title: " + newPage.title);
});

load(options)

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

load(options?: OneNote.Interfaces.PageLoadOptions): OneNote.Page;

参数

options
OneNote.Interfaces.PageLoadOptions

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

返回

load(propertyNames)

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

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

参数

propertyNames

string | string[]

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

返回

示例

await OneNote.run(async (context) => {

    // Gets the active page.
    const activePage = context.application.getActivePage();

    // Queue a command to add a new page after the active page.
    const pageContents = activePage.contents;

    // Queue a command to load the pageContents to access its data.
    context.load(pageContents);

    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync()
    for(let i=0; i < pageContents.items.length; i++) {
        const pageContent = pageContents.items[i];
        if (pageContent.type == "Outline") {
            console.log("Found an outline");
        } else if (pageContent.type == "Image") {
            console.log("Found an image");
        } else if (pageContent.type == "Other") {
            console.log("Found a type not supported yet.");
        }
    }
});

load(propertyNamesAndPaths)

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

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

参数

propertyNamesAndPaths

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

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

返回

set(properties, options)

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

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

参数

properties
OneNote.Interfaces.PageUpdateData

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

options
OfficeExtension.UpdateOptions

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

返回

void

set(properties)

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

set(properties: OneNote.Page): void;

参数

properties
OneNote.Page

返回

void

toJSON()

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

toJSON(): OneNote.Interfaces.PageData;

返回

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 的 context.trackedObjects.add(thisObject)简写。 如果跨 .sync 调用和在“.run”批处理的顺序执行之外使用此对象,并在对对象设置属性或调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪的对象集合。

track(): OneNote.Page;

返回

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 的 context.trackedObjects.remove(thisObject)简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存释放生效之前,需要调用 。context.sync()

untrack(): OneNote.Page;

返回