OneNote.Page class
表示一个 OneNote 页面。
注解
使用方
属性
| class |
获取到页面的 ClassNotebookPageSource。 |
| client |
页面的客户端 URL。 |
| contents | 页面上 PageContent 对象的集合。 只读 |
| context | 与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。 |
| id | 获取页面的 ID。 |
| ink |
页面上墨迹的文本解释。 如果没有墨迹分析信息,则返回 null。 |
| page |
获取或设置页面的缩进级别。 |
| parent |
获取包含页面的分区。 |
| title | 获取或设置页面的标题。 |
| web |
页面的 Web URL。 |
方法
| add |
添加 Outline 至指定位置的页面。 |
| analyze |
返回一个包含节点 ID 和内容的 HTML 格式的 JSON 字符串。 |
| apply |
插入包含翻译内容的新页面。 |
| copy |
将此页复制到指定的分区中。 |
| copy |
将此页面复制到指定部分并设置 ClassNotebookPageSource。 |
| get |
获取 REST API ID。 |
| has |
页面是否有内容标题。 |
| insert |
在当前分区之前或之后插入一个新的页面。 |
| insert |
在当前分区之前或之后插入一个新的页面。 |
| load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| set(properties, options) | 同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。 |
| set(properties) | 基于现有加载的对象,同时在对象上设置多个属性。 |
| toJSON() | 覆盖 JavaScript |
| track() | 根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果在调用中 |
| untrack() | 释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 需要在内存释放生效之前调用 |
属性详细信息
classNotebookPageSource
获取到页面的 ClassNotebookPageSource。
readonly classNotebookPageSource: string;
属性值
string
注解
clientUrl
contents
页面上 PageContent 对象的集合。 只读
readonly contents: OneNote.PageContentCollection;
属性值
注解
context
id
inkAnalysisOrNull
页面上墨迹的文本解释。 如果没有墨迹分析信息,则返回 null。
readonly inkAnalysisOrNull: OneNote.InkAnalysis;
属性值
注解
pageLevel
parentSection
title
webUrl
方法详细信息
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 。
返回
注解
示例
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()
返回一个包含节点 ID 和内容的 HTML 格式的 JSON 字符串。
analyzePage(): OfficeExtension.ClientResult<string>;
返回
OfficeExtension.ClientResult<string>
注解
applyTranslation(translatedContent)
插入包含翻译内容的新页面。
applyTranslation(translatedContent: string): void;
参数
- translatedContent
-
string
页面的翻译内容。
返回
void
注解
copyToSection(destinationSection)
将此页复制到指定的分区中。
copyToSection(destinationSection: OneNote.Section): OneNote.Page;
参数
- destinationSection
- OneNote.Section
要将此页复制到的分区。
返回
注解
示例
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
返回
注解
getRestApiId()
获取 REST API ID。
getRestApiId(): OfficeExtension.ClientResult<string>;
返回
OfficeExtension.ClientResult<string>
注解
示例
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>;
返回
OfficeExtension.ClientResult<boolean>
注解
insertPageAsSibling(location, title)
在当前分区之前或之后插入一个新的页面。
insertPageAsSibling(location: OneNote.InsertLocation, title: string): OneNote.Page;
参数
- location
- OneNote.InsertLocation
相对于当前页面的新页面的位置。
- title
-
string
新页面的标题。
返回
注解
示例
// Insert a new page as a sibling before the current page.
await OneNote.run(async (context) => {
const application = context.application;
const currentPage = application.getActivePage();
const insertedPage = currentPage.insertPageAsSibling(OneNote.InsertLocation.before, 'Rubric grading page');
await context.sync();
application.navigateToPage(insertedPage);
await context.sync();
});
insertPageAsSibling(location, title)
在当前分区之前或之后插入一个新的页面。
insertPageAsSibling(location: "Before" | "After", title: string): OneNote.Page;
参数
- location
-
"Before" | "After"
相对于当前页面的新页面的位置。
- title
-
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 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;
参数
为要加载的对象属性提供选项。
返回
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)
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;