跳到主要内容

AddCaptionCrossRef

向当前段落添加题注交叉引用。 💡 请注意,此段落必须在文档中。

语法

expression.AddCaptionCrossRef(sCaption, sRefType, oParaTo, bLink, bAboveBelow);

expression - 表示 ApiParagraph 类的变量。

参数

名称必需/可选数据类型默认值描述
sCaption必需CaptionLabel | string题注标签(“公式”、“图”、“表”或其他题注标签)。
sRefType必需captionRefTo要插入的题注引用的文本或数值。
oParaTo必需ApiParagraph要引用的题注段落(必须在文档中)。
bLink可选booleantrue指定引用是否作为超链接插入。
bAboveBelow可选booleanfalse指定是否应包含表示引用位置的“上方/下方”字样(仅与 “pageNum” sRefType 一起使用)。

返回值

boolean

示例

在文档中插入链接到图形题注的交叉引用。

// How do I add a reference to a numbered caption from another paragraph in a document?

// Point readers to a specific captioned figure using an automated cross-reference link in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let drawing = Api.CreateImage(
'https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png',
60 * 36000, 60 * 36000
);
paragraph.AddDrawing(drawing);
paragraph = Api.CreateParagraph();
doc.Push(paragraph);
paragraph.AddCaption('', 'Figure', false, 'Arabic', false, undefined, 'hyphen');
paragraph = Api.CreateParagraph();
doc.Push(paragraph);
paragraph.AddText('Link to ');
let captionParagraphs = doc.GetAllCaptionParagraphs('Figure');
paragraph.AddCaptionCrossRef('Figure', 'entireCaption', captionParagraphs[0], true, false);