跳到主要内容

GetTextRange

返回表示当前超链接中所含部分文本的 ApiTextRange 对象。

语法​

expression.GetTextRange(start, end);

expression - 表示 ApiHyperlink 类的变量。

参数​

名称必需/可选数据类型默认值描述
start可选number0相对于超链接的起始字符位置(从 0 开始,包含该位置)。
end可选number结束字符位置(从 0 开始,不包含该位置)。默认为超链接末尾。

返回值​

ApiTextRange | null

示例​

通过文本区域将幻灯片上图形中超链接的文本设置为斜体。

// A hyperlink keeps its own runs, and the range covers exactly the text of the link.

// Take the range of the whole hyperlink text and apply italic to it.

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("rect", 300 * 36000, 130 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);
slide.AddObject(shape);

const docContent = shape.GetDocContent();
const paragraph = docContent.GetElement(0);
paragraph.AddText("Open ");
const hyperlink = paragraph.AddHyperlink("https://www.onlyoffice.com", "ONLYOFFICE");

const range = hyperlink.GetTextRange();
range.SetItalic(true);