获取sheet表单里的有效行数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取sheet表单里的有效行数相关的知识,希望对你有一定的参考价值。

public int getRealRowNum(Sheet sheet) {
        int rowNum = sheet.getLastRowNum()-1;
        while(rowNum > 0 ){
            Row row = sheet.getRow(rowNum+1);
            if (row != null) {
                for (Cell cell : row) {
                    if (!StringUtils.isEmpty(getCellValue(cell))); 
                        return rowNum;
                }
            }
            rowNum--;
        }
        return rowNum;
    }
使用POI读取EXCEL时,使用getLastRowNum()方法会把没有值的行也获取到(比如行中有空格)。空行并没有意义,此方法返回有效的行数。

以上是关于获取sheet表单里的有效行数的主要内容,如果未能解决你的问题,请参考以下文章