poi版本4.0及以上判断单元格为空

今天研究easyexcel,导入依赖后,发现之前的导入excel数据代码出现错误,判断单元格为空的方法爆红了。原来是easyexcel用的高板本poi jar包覆盖了旧的poi版本。而以前的一些方法被废除了。

版本4.0以上废除以下判断单元格为空的方法

if(cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK) {
	nullCellNum ++;
}

新的判断空单元格方法如下:

if (null == cell || cell.getCellType().equals(CellType.BLANK)) {
   nullCellNum ++;
   continue;
}

附判断excel空行的方法(整行都为空时,停止遍历取值)

//判断row是否为空
    public static boolean isRowEmpty(Row row) {
        if (null == row) {
            return true;
        }
        int firstCellNum = row.getFirstCellNum();   //第一个列位置
        int lastCellNum = row.getLastCellNum();     //最后一列位置
        int nullCellNum = 0;    //空列数量
        for (int c = firstCellNum; c < lastCellNum; c++) {
            Cell cell = row.getCell(c);
            if (null == cell || cell.getCellType().equals(CellType.BLANK)) {
                nullCellNum ++;
                continue;
            }
            cell.setCellType(CellType.STRING);
            String cellValue = cell.getStringCellValue().trim();
            if (StringUtils.isEmpty(cellValue)) {
                nullCellNum ++;
            }
        }
        //所有列都为空
        if (nullCellNum == (lastCellNum - firstCellNum)) {
            return true;
        }
        return false;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值