跳到主要内容

AddHyperlink

向指定范围添加超链接。

语法​

expression.AddHyperlink(link, screenTipText, bookmarkName);

expression - 表示 ApiRange 类的变量。

参数​

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

返回值​

ApiHyperlink | null | undefined

示例​

将文档中选定的文本部分转换为可点击的超链接。

// How do I attach a web address to a specific word or phrase in a document?

// Make a passage navigable by binding it to an external URL in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("ONLYOFFICE Document Builder");
let range = doc.GetRange(0, 11);
range.AddHyperlink("https://www.onlyoffice.com/", "Main portal");