我一遍又一遍地扫描这个论坛并尝试了这里提到的每一种方法,仍然无法让Apache POI更改以填充我的Excel文档的背景颜色。
这是我的代码:
errorOccured = true;
XSSFCellStyle cs = workbook.createCellStyle();
cs.setFillBackgroundColor(IndexedColors.RED.getIndex());
row.getCell(0).setCellStyle(cs);
你知道为什么这不起作用吗?让row.getCell(0)
充满红色(背景色)的正确方法是什么?
谢谢!
使用前景色而不是背景色。
errorOccured = true;
XSSFCellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(IndexedColors.RED.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
row.getCell(0).setCellStyle(style);
这将用RED填充单元格背景颜色。