SetColor
设置当前文本块的文本颜色。
语法
expression.SetColor(color);
expression - 表示 ApiRun 类(文本块)的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 默认值 | 描述 |
|---|---|---|---|---|
| color | 必需 | ApiColor | 文本颜色。 |
返回值
示例
使用十六进制值更改电子表格中文本运行的字体颜色。
// How do I set a specific color for text inside a shape in a spreadsheet?
// Apply a custom hex color to a run to visually distinguish it from surrounding text in a spreadsheet.
let worksheet = Api.GetActiveSheet();
let fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
let stroke = Api.CreateStroke(0, Api.CreateNoFill());
let shape = worksheet.AddShape(
'flowChartOnlineStorage',
Api.MillimetersToEmus(120), Api.MillimetersToEmus(70),
fill, stroke,
0, Api.MillimetersToEmus(2), 0, Api.MillimetersToEmus(3)
);
let content = shape.GetContent();
let paragraph = content.GetElement(0);
let run = Api.CreateRun();
run.AddText('This is a text run with the font color set to gray.');
paragraph.AddElement(run);
run.SetColor(Api.HexColor('#808080'));