Apache POI provides two ways to access rows and cells in an Excel file. One of them is an iterator that gives you all the records, and the other - by index. (The POI will also tell you the start / end rows / columns). An iterator is often easier to use, but both are equally fast.
If you have special string selection requirements, I would suggest using the latter. Your code will look something like this:
int FIRST_ROW_TO_GET = 2; // 0 based Sheet s = wb.getSheetAt(0); for (int i = FIRST_ROW_TO_GET; i < s.getLastRowNum(); i++) { Row row = s.getRow(i); if (row == null) { // The whole row is blank } else { for (int cn=row.getFirstCellNum(); cn<row.getLastCellNum(); cn++) { Cell c = row.getCell(cn, Row.RETURN_BLANK_AS_NULL); if (c == null) { // The cell is empty } else { // Process the cell } } } }
Gagravarr
source share