Java Apache POI 3.7 XWPFTable单元格颜色更改

时间:2014-09-23 10:37:43

标签: java ms-word apache-poi

我正在尝试使用Java Apache POI 3.7在word文档中创建一个表,我需要更改该表的单元格颜色。我使用XWPFTable但是没有办法改变单元格的颜色。任何人都可以建议进行黑客操作吗?

    XWPFTable tableVersion = document.createTable(); 
    XWPFTableRow tableOneRowVersion = tableVersion.createRow();
    tableOneRowVersion.getCell(0).setText("Version");

1 个答案:

答案 0 :(得分:2)

参考:https://poi.apache.org/apidocs/org/apache/poi/xwpf/usermodel/XWPFTableCell.html

例如:

XWPFTable tableVersion = document.createTable(); 
XWPFTableRow tableOneRowVersion = tableVersion.createRow();
tableOneRowVersion.getCell(0).setColor("000000");
tableOneRowVersion.getCell(0).setText("Version");

确保以十六进制格式设置颜色...