Word.Pane class
代表一个窗格。 对象 Pane 是窗格集合的成员。 窗格集合包括单个窗口的所有窗口窗格。
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/get-pages.yaml
await Word.run(async (context) => {
// Gets the first paragraph of each page.
console.log("Getting first paragraph of each page...");
// Get the active window.
const activeWindow: Word.Window = context.document.activeWindow;
activeWindow.load();
// Get the active pane.
const activePane: Word.Pane = activeWindow.activePane;
activePane.load();
// Get all pages.
const pages: Word.PageCollection = activePane.pages;
pages.load();
await context.sync();
// Get page index and paragraphs of each page.
const pagesIndexes = [];
const pagesNumberOfParagraphs = [];
const pagesFirstParagraphText = [];
for (let i = 0; i < pages.items.length; i++) {
const page = pages.items[i];
page.load("index");
pagesIndexes.push(page);
const paragraphs = page.getRange().paragraphs;
paragraphs.load("items/length");
pagesNumberOfParagraphs.push(paragraphs);
const firstParagraph = paragraphs.getFirst();
firstParagraph.load("text");
pagesFirstParagraphText.push(firstParagraph);
}
await context.sync();
for (let i = 0; i < pagesIndexes.length; i++) {
console.log(`Page index: ${pagesIndexes[i].index}`);
console.log(`Number of paragraphs: ${pagesNumberOfParagraphs[i].items.length}`);
console.log("First paragraph's text:", pagesFirstParagraphText[i].text);
}
});
属性
| context | 与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。 |
| pages | 获取窗格中页面的集合。 |
| pages |
|
方法
| get |
获取窗口中的下一个窗格。 如果此窗格是最后一个 |
| get |
获取下一个窗格。 如果此窗格是最后一个窗格,则此方法将返回对象,其 |
| load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| toJSON() | 重写 JavaScript |
| track() | 根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果跨 |
| untrack() | 释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存发布生效之前,需要调用 |
属性详细信息
context
pages
获取窗格中页面的集合。
readonly pages: Word.PageCollection;
属性值
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/get-pages.yaml
await Word.run(async (context) => {
// Gets the first paragraph of each page.
console.log("Getting first paragraph of each page...");
// Get the active window.
const activeWindow: Word.Window = context.document.activeWindow;
activeWindow.load();
// Get the active pane.
const activePane: Word.Pane = activeWindow.activePane;
activePane.load();
// Get all pages.
const pages: Word.PageCollection = activePane.pages;
pages.load();
await context.sync();
// Get page index and paragraphs of each page.
const pagesIndexes = [];
const pagesNumberOfParagraphs = [];
const pagesFirstParagraphText = [];
for (let i = 0; i < pages.items.length; i++) {
const page = pages.items[i];
page.load("index");
pagesIndexes.push(page);
const paragraphs = page.getRange().paragraphs;
paragraphs.load("items/length");
pagesNumberOfParagraphs.push(paragraphs);
const firstParagraph = paragraphs.getFirst();
firstParagraph.load("text");
pagesFirstParagraphText.push(firstParagraph);
}
await context.sync();
for (let i = 0; i < pagesIndexes.length; i++) {
console.log(`Page index: ${pagesIndexes[i].index}`);
console.log(`Number of paragraphs: ${pagesNumberOfParagraphs[i].items.length}`);
console.log("First paragraph's text:", pagesFirstParagraphText[i].text);
}
});
pagesEnclosingViewport
PageCollection获取窗格的视区中显示的 。 如果页面在窗格中部分可见,则返回整个页面。
readonly pagesEnclosingViewport: Word.PageCollection;
属性值
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/35-ranges/get-pages.yaml
await Word.run(async (context) => {
// Gets the pages enclosing the viewport.
// Get the active window.
const activeWindow: Word.Window = context.document.activeWindow;
activeWindow.load();
// Get the active pane.
const activePane: Word.Pane = activeWindow.activePane;
activePane.load();
// Get pages enclosing the viewport.
const pages: Word.PageCollection = activePane.pagesEnclosingViewport;
pages.load();
await context.sync();
// Log the number of pages.
const pageCount = pages.items.length;
console.log(`Number of pages enclosing the viewport: ${pageCount}`);
// Log index info of these pages.
const pagesIndexes = [];
for (let i = 0; i < pageCount; i++) {
const page = pages.items[i];
page.load("index");
pagesIndexes.push(page);
}
await context.sync();
for (let i = 0; i < pagesIndexes.length; i++) {
console.log(`Page index: ${pagesIndexes[i].index}`);
}
});
方法详细信息
getNext()
获取窗口中的下一个窗格。 如果此窗格是最后一个 ItemNotFound 窗格,则引发错误。
getNext(): Word.Pane;
返回
注解
getNextOrNullObject()
获取下一个窗格。 如果此窗格是最后一个窗格,则此方法将返回对象,其 isNullObject 属性设置为 true。 有关详细信息,请参阅 *OrNullObject 方法和属性。
getNextOrNullObject(): Word.Pane;
返回
注解
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(options?: Word.Interfaces.PaneLoadOptions): Word.Pane;
参数
- options
- Word.Interfaces.PaneLoadOptions
提供要加载对象的属性的选项。
返回
load(propertyNames)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNames?: string | string[]): Word.Pane;
参数
- propertyNames
-
string | string[]
逗号分隔的字符串或指定要加载的属性的字符串数组。
返回
load(propertyNamesAndPaths)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.Pane;
参数
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。
返回
toJSON()
重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。
JSON.stringify
(,依次调用toJSON传递给它的 对象的 方法。) 虽然原始Word.Pane对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Word.Interfaces.PaneData) ,其中包含从原始对象加载的任何子属性的浅表副本。
toJSON(): Word.Interfaces.PaneData;
返回
track()
根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果跨 .sync 调用和“.run”批处理的顺序执行外部使用此对象,并在设置属性或调用对象方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将该对象添加到跟踪的对象集合。 如果此对象是集合的一部分,则还应跟踪父集合。
track(): Word.Pane;
返回
untrack()
释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存发布生效之前,需要调用 context.sync() 。
untrack(): Word.Pane;