Word.TableOfFiguresCollection class
方法
| add(range, options) | 在指定范围内向文档添加图形表。 |
| load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| mark |
在图表中标记条目的指定范围之后插入目录 条目 (TC) 字段 。 |
| toJSON() | 覆盖 JavaScript |
| track() | 根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果在调用中 |
| untrack() | 释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 需要在内存释放生效之前调用 |
属性详细信息
context
items
方法详细信息
add(range, options)
在指定范围内向文档添加图形表。
add(range: Word.Range, options?: Word.TableOfFiguresAddOptions): Word.TableOfFigures;
参数
- range
- Word.Range
将添加图表表格的范围。 如果范围未折叠,则由图表替换范围。
- options
- Word.TableOfFiguresAddOptions
可选。 用于配置图表的选项。
返回
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/42-reference-tables/table-of-figures.yaml
// Adds a table of figures at the start of the document.
await Word.run(async (context) => {
const documentBody: Word.Body = context.document.body;
const tablesOfFigures: Word.TableOfFiguresCollection = context.document.tablesOfFigures;
const insertionRange: Word.Range = documentBody.getRange(Word.RangeLocation.start);
const tableOptions: Word.TableOfFiguresAddOptions = {
captionLabel: "Figure",
includeLabel: true,
includePageNumbers: true,
rightAlignPageNumbers: true,
tableId: "F",
useFields: true,
};
const tableOfFigures: Word.TableOfFigures = tablesOfFigures.add(insertionRange, tableOptions);
await context.sync();
console.log("Created a table of figures.");
});
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(options?: Word.Interfaces.TableOfFiguresCollectionLoadOptions & Word.Interfaces.CollectionLoadOptions): Word.TableOfFiguresCollection;
参数
为要加载的对象属性提供选项。
返回
load(propertyNames)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNames?: string | string[]): Word.TableOfFiguresCollection;
参数
- propertyNames
-
string | string[]
指定要加载的属性的逗号分隔的字符串或字符串数组。
返回
load(propertyNamesAndPaths)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Word.TableOfFiguresCollection;
参数
- propertyNamesAndPaths
- OfficeExtension.LoadOption
propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。
返回
markTocEntry(range, options)
在图表中标记条目的指定范围之后插入目录 条目 (TC) 字段 。
markTocEntry(range: Word.Range, options?: Word.TableOfContentsMarkEntryOptions): Word.Field;
参数
- range
- Word.Range
将插入 TC 字段的范围。
可选。 用于标记条目的选项。
返回
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/42-reference-tables/table-of-figures.yaml
// Marks each figure paragraph as a table entry.
await Word.run(async (context) => {
const documentBody: Word.Body = context.document.body;
const tablesOfFigures: Word.TableOfFiguresCollection = context.document.tablesOfFigures;
const paragraphs: Word.ParagraphCollection = documentBody.paragraphs;
paragraphs.load("items/text");
await context.sync();
const figureParagraphs: Word.Paragraph[] = paragraphs.items.filter((paragraph: Word.Paragraph) =>
paragraph.text.startsWith("Figure ")
);
figureParagraphs.forEach((figureParagraph: Word.Paragraph) => {
const entryOptions: Word.TableOfContentsMarkEntryOptions = {
entry: figureParagraph.text,
level: 1,
tableId: "F",
};
const entryRange: Word.Range = figureParagraph.getRange();
tablesOfFigures.markTocEntry(entryRange, entryOptions);
});
await context.sync();
console.log(`Marked ${figureParagraphs.length} table of figures entries.`);
});
toJSON()
覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Word.TableOfFiguresCollection 对象是 API 对象,但该 toJSON 方法返回一个纯 JavaScript 对象, (类型为 Word.Interfaces.TableOfFiguresCollectionData) ,其中包含一个“items”数组,其中包含从集合的 items 中加载的任何属性的浅层副本。
toJSON(): Word.Interfaces.TableOfFiguresCollectionData;
返回
track()
根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果在调用中 .sync 使用此对象,并且在“.run”批处理的顺序执行之外使用此对象,并且在设置属性或对对象调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪对象集合。 如果此对象是集合的一部分,您还应跟踪父集合。
track(): Word.TableOfFiguresCollection;
返回
untrack()
释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 需要在内存释放生效之前调用 context.sync() 。
untrack(): Word.TableOfFiguresCollection;