How to get row count in an Excel file using POI library?

前端 未结 7 2143
执念已碎
执念已碎 2020-12-08 09:37

Guys I\'m currently using the POI 3.9 library to work with excel files. I know of the getLastRowNum() function, which returns a number of rows in an Excel file.

7条回答
  •  独厮守ぢ
    2020-12-08 09:59

    To find last data row, in case you created table template in excel where it is filled partially or in between rows are empty. Logic:

    int count = 0;
    int emptyrow=0;
    int irow=0;
    while (rowIterator.hasNext()) {
        row = (Row) rowIterator.next();
        if (count != 0 && !checkIfRowIsEmpty(row)) { }
        else{
            if(count!=0 && emptyrow==irow){
                emptyrow++;
            }else{
                emptyrow=0;
                irow=0;
            }
        }
        if(emptyrow>0){
            irow++;
        }
        if(emptyrow>3){
            break;
        }
        count++;
    }
    

提交回复
热议问题