Skip to main content

AddHyperlink

Adds a hyperlink to the current text range.

Syntax​

expression.AddHyperlink(link, screenTipText);

expression - A variable that represents an ApiTextRange class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
linkRequiredstringThe link address. Accepts an external URL (http, https, mailto, ftp) or an internal link. In the presentation editor, the internal link is one of the slide actions: "ppaction://hlinkshowjump?jump=firstslide", "ppaction://hlinkshowjump?jump=lastslide", "ppaction://hlinkshowjump?jump=nextslide", "ppaction://hlinkshowjump?jump=previousslide", "ppaction://hlinksldjumpslide{N}" (N is the zero-based slide index), "ppaction://hlinkfile?file={path}" (opens an external file). In the spreadsheet editor, the internal link is "#" followed by a cell range or a defined name, for example, "#Sheet1!A1" or "#MyName".
screenTipTextRequiredstringThe screen tip text.

Returns​

ApiHyperlink | null | undefined

Example​

Turn a fragment of text into a hyperlink in a shape on a worksheet.

// The range must stay within a single paragraph, and besides a web address the link can point to a cell range in the workbook, for example, "#Sheet1!A1".

// Turn the word "here" into a link to the ONLYOFFICE website.

let worksheet = Api.GetActiveSheet();
let fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
let stroke = Api.CreateStroke(0, Api.CreateNoFill());
let shape = worksheet.AddShape("rect", 200 * 36000, 80 * 36000, fill, stroke, 3, 0, 1, 0);

let docContent = shape.GetContent();
let paragraph = docContent.GetElement(0);
paragraph.AddText("Click here to learn more");

let range = shape.GetTextRange();

let link = range.GetRange(6, 10);
link.AddHyperlink("https://www.onlyoffice.com", "ONLYOFFICE");