项目场景:
项目中需要设置单元格背景色,但是设置颜色不生效
问题描述
查了资料,需要设置fillttern设置之后还是一直不生效,背景色还是空白
CellStyle styleMain = workbook.createCellStyle();
styleMain.setFillBackgroundColor(IndexedColors.GREEN.getIndex());
styleMain.setFillPattern(FillPatternType.SOLID_FOREGROUND);
原因分析:
查了资料csdn上说的都是大同小异看起来也都是这样设置的,最后找到这篇博文https://blog.csdn.net/q648747613/article/details/118024644才发现自己错在哪。
这里强调一下,希望能为遇到同样问题的同学节约一点时间正确设置的方法
CellStyle styleMain = workbook.createCellStyle(); styleMain.setFillForegroundColor(IndexedColors.GREEN.getIndex()); styleMain.setFillPattern(FillPatternType.SOLID_FOREGROUND);
特别需要注意
setFillForegroundColor
而不是