POI设置单元格颜色及枚举颜色对照

本文介绍了如何使用Java POI库来设置Excel单元格的颜色,并提供了完整的代码示例。同时,文章详细列举了颜色代码与枚举的对应关系,帮助开发者更好地理解和使用。
摘要由CSDN通过智能技术生成

设置单元格颜色代码:

CellStyle st = workbook.createCellStyle();
st.setFillForegroundColor(clr.getIndex());
st.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell.setCellStyle(st);

以下代码遍历全部颜色并输出对照:

        Sheet sheet = workbook.createSheet("name");
        int row = 0;
        int col = 0;
        Row prow = sheet.createRow(row);
        for(IndexedColors clr : IndexedColors.values()){
            Cell cell = prow.createCell(col);
            cell.setCellValue(clr.toString());

            cell = prow.createCell(col+1);
            CellStyle st = workbook.createCellStyle();
            st.setFillForegroundColor(clr.getIndex());
            st.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            cell.setCellStyle(st);

            col+=3;

            if(col >= 10){
                col = 0;
                row++;
                prow = sheet.createRow(row);
            }
        }

颜色及代码枚举对应关系:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值