+-
java – 无法设置填充颜色Apache POI Excel工作簿
我一遍又一遍地扫描这个论坛并尝试了这里提到的每一种方法,仍然无法让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填充单元格背景颜色.

点击查看更多相关文章

转载注明原文:java – 无法设置填充颜色Apache POI Excel工作簿 - 乐贴网