I am using Apache POI java and want to get the total number of rows that are not empty. I successfully processed the whole row with all its columns. Now I assume that I am getting an excel sheet with multiple rows, not a single row ... so how to do this? I thought to get the total number of rows (int n), and then loop until i <= n, but not sure.
Suggestions are welcome :)
Note. The Apache POI version is 3.8. I am not dealing with the Xlsx format ... only xls.
Yes, I tried this code, but got 20 in response .... which is impossible, I have only 5 lines
FileInputStream fileInputStream = new FileInputStream("COD.xls"); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet worksheet = workbook.getSheet("COD"); HSSFRow row1 = worksheet.getRow(3); Iterator rows = worksheet.rowIterator(); int noOfRows = 0; while( rows.hasNext() ) { HSSFRow row = (HSSFRow) rows.next(); noOfRows++; } System.out.println("Number of Rows: " + noOfRows);
source share