I have to get all the cell values from two columns, all rows. (Eg: C,D columns) and show it in my java app.
But I'm not getting the exact number of rows.
There are only 4 rows but it shows 7 because of which i'm getting null pointer exception
Please review the code and suggest.
Which version of POI are you using? Is getPhysicalRows the only method for getting a number of rows? Is there another similar API call? You also might need to check each row for null and skip processing that row if it is.
Read the javadocs of the getPhysicalNumberOfRows method. Then search for other occurrences of that method name on the same page to find the method that you should be using instead. Be sure to read the javadocs of that method as well.
Note that the same applies to HSSFRow.getPhysicalNumberOfCells.
machines help you to do more, but experience less. Experience this tiny ad: