跳到主要内容

Add

向文档添加图表目录并返回该图表目录。

备注

此功能仅在 ONLYOFFICE Docs 付费版本中可用。

语法​

expression.Add(oTofPr, oRange);

expression - 表示 ApiTablesOfFigures 类的变量。

参数​

名称必需/可选数据类型默认值描述
oTofPr可选TofPr{}图表目录属性。
oRange可选ApiRange图表目录要替换的范围。如果省略,则在当前位置插入图表目录。

返回值​

ApiTableOfFigures | null

示例​

向文档插入替换指定区域的新图表目录。

// Add a captioned figure, then place an anchor paragraph where the table of figures should appear.

// Add the table of figures to the collection, replacing the anchor range, and return it.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("Figure 1");
paragraph.AddCaption(" - Sample figure", "Figure", false, "Arabic", false, undefined, "hyphen");
let anchor = Api.CreateParagraph();
anchor.AddText("Table of figures goes here");
doc.Push(anchor);
let tablesOfFigures = doc.GetTablesOfFigures();
let range = anchor.GetRange();
let tof = tablesOfFigures.Add({"ShowPageNums": true, "RightAlgn": true, "LeaderType": "dot", "FormatAsLinks": true, "BuildFrom": "Figure", "LabelNumber": true, "TofStyle": "distinctive"}, range);