java poi - excel cell 设置自定义颜色
作者:互联网
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
标签:cellStyle,java,wb,自定义,color,excel,setFillPattern,new,font 来源: https://www.cnblogs.com/c2g5201314/p/16664431.html