首页 > 编程语言 >java poi - excel cell 设置自定义颜色

java poi - excel cell 设置自定义颜色

时间:2022-09-07 10:33:23浏览次数:67  
标签:cellStyle java wb 自定义 color excel setFillPattern new font

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
From: https://www.cnblogs.com/c2g5201314/p/16664431.html

相关文章