Saturday, 23 January 2016

How to get column number from excel sheet using apache poi

We can get column number by using below different options






Option1:
int noOfColumns = sh.getRow(0).getPhysicalNumberOfCells();
or


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


There is some difference between above two options

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)
Option 2 just gives you the index of last column. Hence done 'getLastCellNum()'

No comments:

Post a Comment