跳到主要内容

SetColor

设置当前文本块的文本颜色。

语法

expression.SetColor(color);

expression - 表示 ApiRun 类(文本块)的变量。

参数

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

返回值

ApiTextPr

示例

此示例为当前文本块设置文本颜色。

// How to change text color.

// Create a new text run and change its font color.

const doc = Api.GetDocument();
const paragraph = doc.GetElement(0);

const firstRun = Api.CreateRun();
firstRun.AddText('This is a text run with the font color set to orange.');
firstRun.SetColor(Api.HexColor('#FF6F3D'));
paragraph.AddElement(firstRun);

const secondRun = Api.CreateRun();
secondRun.AddText('The text uses a bluish color created with HexColor method.');
const hexColor = Api.HexColor('#219ebc');
secondRun.SetColor(hexColor);
paragraph.AddElement(secondRun);