1.必须调用设置前景色的方法来设置背景色;
2.必须调用 setFillPattern();
3.代码如下:
//cl.setFillBackgroundColor(IndexedColors.YELLOW.getIndex()); 调用背景色方法没用
cellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
用的是poi-3.9,SXXF创建的单元格,其他的不知道是不是这样
如果觉得《POI 导出 excel 设置单元格背景色 的坑》对你有帮助,请点赞、收藏,并留下你的观点哦!