跳到主要内容

CreateRange

创建元素范围。 如果不指定起始和结束位置,将从整个元素获取范围。

语法

expression.CreateRange(element, start, end);

expression - 表示 Api 类的变量。

参数

名称必需/可选数据类型默认值描述
element必需将从中获取范围的元素。
start必需范围起始位置。
end必需范围结束位置。

返回值

ApiRange | null

示例

通过选择文档中的文本范围将段落的前几个字符设为粗体。

// How do I select a specific portion of a paragraph and make it bold in a document?

// Apply bold formatting to the opening words of a paragraph without affecting the rest of the text in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("ONLYOFFICE Document Builder");
Api.CreateRange(paragraph, 0, 11).SetBold(true);