跳到主要内容

AddHyperlink

向当前文本块添加超链接。

语法

expression.AddHyperlink(sLink, sScreenTipText, sBookmarkName);

expression - 表示 ApiRun 类(文本块)的变量。

参数

名称必需/可选数据类型默认值描述
sLink必需string链接地址。
sScreenTipText必需string屏幕提示文本。
sBookmarkName必需string书签名称

返回值

ApiHyperlink

示例

将文档中的文本运行转换为指向网址的可点击链接。

// How do I make a piece of text open a website when clicked in a document?

// Attach a URL and a tooltip title to a run of text so readers can follow it in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let run = Api.CreateRun();
run.AddText("ONLYOFFICE Document Builder");
paragraph.AddElement(run);
run.AddHyperlink("https://www.onlyoffice.com", "main page");