跳到主要内容

SetColor

为当前文本范围设置文本颜色。

语法

expression.SetColor(color);

expression - 表示 ApiRange 类的变量。

参数

名称必需/可选数据类型默认值描述
color必需ApiColor文本颜色。

返回值

ApiRange | null

示例

此示例为文本范围设置文本颜色。

// How to color the text of the range.

// Set the text color to middle washed rose.

const doc = Api.GetDocument();
const firstParagraph = doc.GetElement(0);
firstParagraph.AddText('ONLYOFFICE Document Builder');

const companyRange = doc.GetRange(1, 11);
companyRange.SetColor(Api.HexColor('#FF6F3D'));

const productRange = doc.GetRange(12, 30);
const themeColor = Api.ThemeColor('accent1');
productRange.SetColor(themeColor);