poi设置背景颜色,设置颜色不起作用
Workbook workbook = new XSSFWorkbook();
CellStyle cellStyle = workbook.createCellStyle();
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
CellStyle style = workbook.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.DARK_GREEN.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
解决办法:
设置setFillForegroundColor还需要设置一下setFillPattern,如果只设置背景颜色是不起作用的,太坑了。
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
顺便写一下设置颜色的3种方式
1.RGB
style.setFillForegroundColor(new XSSFColor(new Color(0, 0, 0)));
2.颜色的16进制
style.setFillForegroundColor(Color.decode("#D8D8D8"));
3.POI里面固定的一些颜色
XSSFColor clr = new XSSFColor();
clr.setIndexed(IndexedColors.RED.getIndex());
style.setFillForegroundColor(clr);