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.
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++;
}