XSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(new XSSFColor(new Color(195, 227, 255))); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
setFillPattern 必须加,否则 setFillForegroundColor 不生效
简单封装的工具模板
//获取列名格子样式 private static XSSFCellStyle getTitleColsStyle(XSSFWorkbook wb, Color color) { XSSFCellStyle cellStyle = wb.createCellStyle(); // 居中 cellStyle.setAlignment(HorizontalAlignment.CENTER); // 垂直 cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); if (null == color) color = new Color(195, 227, 255); cellStyle.setFillForegroundColor(new XSSFColor(color)); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); XSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 11); cellStyle.setFont(font); //自动转行 cellStyle.setWrapText(true); return cellStyle; }View Code