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

前端 未结 7 2140
执念已碎
执念已碎 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条回答
  •  -上瘾入骨i
    2020-12-08 09:54

    There are two Things you can do

    use

    int noOfColumns = sh.getRow(0).getPhysicalNumberOfCells();
    

    or

    int noOfColumns = sh.getRow(0).getLastCellNum();
    

    There is a fine difference between them

    1. Option 1 gives the no of columns which are actually filled with contents(If the 2nd column of 10 columns is not filled you will get 9)

    2. Option 2 just gives you the index of last column. Hence done 'getLastCellNum()'

提交回复
热议问题