poi合并单元格,没有样式

问题如下:

所有单元格的样式都是带边框的,但是合并之后,图中的红框标识区域样式并没有

样式源码如下:

   public HSSFCellStyle getBorderCellStyle(HSSFWorkbook hWorkbook) {
        HSSFCellStyle cellStyle = hWorkbook.createCellStyle();
        //加边框
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);//下边框
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
        return cellStyle;
    }

解决思路:

合并之后根据合并的单元格坐标再重新设置样式即可

源码:

添加表头之后,重新设置样式,更新行数和列数

private void setCellStyle(int rowIndex, int columnIndex, int toRowIndex, int toColumnIndex, HSSFCellStyle cellStyle) {
        for (int i = rowIndex; i <= toRowIndex; i++) {
            for (int j = columnIndex; j < (toColumnIndex + columnIndex); j++) {
                HSSFRow row = hSheet.getRow(i);
                HSSFCell cell = null;
                if (null != row) {
                    cell = row.getCell(j);
                    if (null == cell) {
                        cell = row.createCell(j);
                        cell.setCellStyle(cellStyle);
                    }
                }
            }
        }
    }

结果:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值