本次用的poi的版本是4.1.2
SXSSFWorkbook wb = new SXSSFWorkbook();
CellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER)
style.setFillForegroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex());// 设置背景色
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
如果是3版本一下
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
上面的单元格颜色对应下面的英语颜色表示,从X1-X49 按顺序对应;
IndexedColors.AQUA.getIndex();
IndexedColors.AUTOMATIC.getIndex();
IndexedColors.BLUE.getIndex();
IndexedColors.BLUE_GREY.getIndex();
IndexedColors.BRIGHT_GREEN.getIndex();
IndexedColors.BROWN.getIndex();
IndexedColors.CORAL.getIndex();
IndexedColors.CORNFLOWER_BLUE.getIndex();
IndexedColors.DARK_BLUE.getIndex();
IndexedColors.DARK_GREEN.getIndex();
IndexedColors.DARK_RED.getIndex();
IndexedColors.DARK_TEAL.getIndex();
IndexedColors.DARK_YELLOW.getIndex();
IndexedColors.GOLD.getIndex();
IndexedColors.GREEN.getIndex();
IndexedColors.GREY_25_PERCENT.getIndex();
IndexedColors.GREY_40_PERCENT.getIndex();
IndexedColors.GREY_50_PERCENT.getIndex();
IndexedColors.GREY_80_PERCENT.getIndex();
IndexedColors.INDIGO.getIndex();
IndexedColors.LAVENDER.getIndex();
IndexedColors.LEMON_CHIFFON.getIndex();
IndexedColors.LIGHT_BLUE.getIndex();
IndexedColors.LEMON_CHIFFON.getIndex();
IndexedColors.LIGHT_BLUE.getIndex();
IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex();
IndexedColors.LIGHT_GREEN.getIndex();
IndexedColors.LIGHT_ORANGE.getIndex();
IndexedColors.LIGHT_TURQUOISE.getIndex();
IndexedColors.LIGHT_YELLOW.getIndex();
IndexedColors.LIME.getIndex();
IndexedColors.MAROON.getIndex();
IndexedColors.OLIVE_GREEN.getIndex();
IndexedColors.ORANGE.getIndex();
IndexedColors.ORCHID.getIndex();
IndexedColors.PALE_BLUE.getIndex();
IndexedColors.PINK.getIndex();
IndexedColors.PLUM.getIndex();
IndexedColors.RED.getIndex();
IndexedColors.ROSE.getIndex();
IndexedColors.ROYAL_BLUE.getIndex();
IndexedColors.SEA_GREEN.getIndex();
IndexedColors.SKY_BLUE.getIndex();
IndexedColors.TAN.getIndex();
IndexedColors.TEAL.getIndex();
IndexedColors.TURQUOISE.getIndex();
IndexedColors.VIOLET.getIndex();
IndexedColors.WHITE.getIndex();
IndexedColors.YELLOW.getIndex();
HSSFCellStyle style = workbook.createCellStyle();
style.setFillBackgroundColor(HSSFColor.AQUA.index);
cell.setCellStyle(style);