跳到主要内容

GetRange

返回表示指定范围中包含的文档部分的 Range 对象。

语法

expression.GetRange(Start, End);

expression - 表示 ApiRange 类的变量。

参数

名称必需/可选数据类型默认值描述
Start可选Number0当前范围中的起始位置索引。
End可选Number-1当前范围中的结束位置索引(如果 <= 0,则范围取到末尾)。

返回值

ApiRange

示例

此示例展示如何获取表示指定范围中包含的文档部分的 Range 对象。

// Get the range from the range indicating its start and end positions.

// Retrieve a range and make them italic.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("ONLYOFFICE Document Builder");
let range1 = doc.GetRange(0, 24);
range1.SetBold(true);
let range2 = range1.GetRange(0, 9);
range2.SetItalic(true);