跳到主要内容

SetColor

设置当前段落的文本颜色。

语法

expression.SetColor(color);

expression - 表示 ApiParagraph 类的变量。

参数

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

返回值

ApiParagraph

示例

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

// Color the paragraph text with orange.

// Get the first paragraph and make its font color orange.

const doc = Api.GetDocument();
const firstParagraph = doc.GetElement(0);
firstParagraph.AddText('This is a paragraph with the font color set to orange.');
firstParagraph.SetColor(Api.HexColor('#FF6F3D'));

const color = Api.HexColor('ff6f3d');
const secondParagraph = Api.CreateParagraph();
secondParagraph.AddText('This text is in same orange color, but created using HexColor method.');
secondParagraph.SetColor(color);
doc.Push(secondParagraph);