private static CellStyle leftStyle(final Workbook exportWorkbook) {CellStyle cellStyleLeft = exportWorkbook.createCellStyle();Font font = exportWorkbook.createFont();font.setFontName("宋体");cellStyleLeft.setFont(font);cellStyleLeft.setAlignment(HorizontalAlignment.LEFT);cellStyleLeft.setVerticalAlignment(VerticalAlignment.CENTER);cellStyleLeft.setBorderBottom(BorderStyle.THIN);cellStyleLeft.setBorderLeft(BorderStyle.THIN);cellStyleLeft.setBorderRight(BorderStyle.THIN);cellStyleLeft.setBorderRight(BorderStyle.THIN);cellStyleLeft.setBorderTop(BorderStyle.THIN);cellStyleLeft.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); // 灰色cellStyleLeft.setFillPattern(FillPatternType.SOLID_FOREGROUND);return cellStyleLeft;}
根据需求设置单元格背景色为灰色,以上代码设置结果为黑色,原因是cellStyleLeft.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); // 灰色
这段代码有问题,改成下面就行,注意页面颜色填充
cellStyleLeft.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); // 灰色