如何在 Java 的 Aspose Word 中更改现有 table 单元格的字体颜色?

How to change font color of an existing table cell in Aspose Word in Java?

我在Aspose word模板中已有table,我想更改单元格内文本的字体颜色。我怎样才能实现它?

CellCollection cellList = row.getCells() 
def i = 0 
Run run; 
Cell cell = cellList.get(i)

我是 Aspose Word 的新手。

请使用以下代码示例更改 table 单元格内文本的颜色。希望对你有帮助。

//Load the document
Document doc = new Document(MyDir + "in.docx");

//Get the first table in the document
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);

//Get the first cell of first row
Cell cell = (Cell)table.getRows().get(0).getCells().get(0);

//Change the color of text
for (Run run : (Iterable<Run>)cell.getChildNodes(NodeType.RUN, true))
{
    run.getFont().setColor(Color.BLUE);
}

//Save the document
doc.save(MyDir + "Out.docx");

我在 Aspose 工作,担任开发人员布道师。