跳到主要内容

GetBackgroundColor

返回当前表格单元格的背景颜色。

语法

expression.GetBackgroundColor();

expression - 表示 ApiTableCell 类的变量。

参数

此方法没有任何参数。

返回值

ApiColor

示例

此示例展示如何设置和获取当前表格单元格的背景颜色。

let doc = Api.GetDocument();
let tableStyle = doc.CreateStyle("CustomTableStyle", "table");
tableStyle.SetBasedOn(doc.GetStyle("Bordered"));
let table = Api.CreateTable(4, 2);
table.SetWidth("percent", 100);
table.SetStyle(tableStyle);

let cell = table.GetRow(0).GetCell(0);
cell.SetBackgroundColor(Api.HexColor('#afafff'));
const backgroundColor = cell.GetBackgroundColor();

let paragraph = doc.GetElement(0);
paragraph.AddText('This paragraph has the same color as the table cell background: ' + backgroundColor.GetHex());
paragraph.SetColor(backgroundColor);
doc.Push(table);