https://issues.apache.org/bugzilla/show_bug.cgi?id=57494
Bug ID: 57494
Summary: Discrepancy between using
XSSFWorkbook.getSheetAt(0).getRowIterator() and
XSSFWorkbook.getSheetAt(0).getRow(#)
Product: POI
Version: 3.8-FINAL
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: POI Overall
Assignee: [email protected]
Reporter: [email protected]
Created attachment 32396
--> https://issues.apache.org/bugzilla/attachment.cgi?id=32396&action=edit
10 row spreadsheet. Second row missing data
The spreadsheet attached is missing the first row of data after the header row.
Creating a XSSFWorkbook(FileInputStream fis) object eliminates the empty row.
The sheet rowsIterator contains only the header and the rest of valid rows in
the spreadsheet. However, trying to access the rows using the sheet getRow(#)
method throws a NullPointerException when trying getSheetAt(0).getRow(1).
Used a testcase to quickly show the issue:
FileInputStream fis = new FileInputStream(new
File("2nd_Row_Missing.xlsx"));
Workbook wb = new XSSFWorkbook(fis);
logger.debug("rowIterator()");
Iterator x = wb.getSheetAt(0).rowIterator();
int i = -1;
while (x.hasNext()) {
i++;
Row row = (Row) x.next();
Iterator y = row.cellIterator();
y.next(); // don't care for first numeric cell
Cell cell = (Cell) y.next(); // I want the second one (string)
logger.debug("row = " + i + ", cell = 1, value = " +
cell.getStringCellValue());
}
logger.debug("getRow()");
logger.debug("row = 0, cell = 1, value = " +
wb.getSheetAt(0).getRow(0).getCell(1).toString());
logger.debug("row = 1, cell = 1, value = null; throws
NullPointerException");
logger.debug("row = 2, cell = 1, value = " +
wb.getSheetAt(0).getRow(2).getCell(1).toString());
logger.debug("row = 3, cell = 1, value = " +
wb.getSheetAt(0).getRow(3).getCell(1).toString());
logger.debug("row = 4, cell = 1, value = " +
wb.getSheetAt(0).getRow(4).getCell(1).toString());
logger.debug("row = 5, cell = 1, value = " +
wb.getSheetAt(0).getRow(5).getCell(1).toString());
logger.debug("row = 6, cell = 1, value = " +
wb.getSheetAt(0).getRow(6).getCell(1).toString());
logger.debug("row = 7, cell = 1, value = " +
wb.getSheetAt(0).getRow(7).getCell(1).toString());
logger.debug("row = 8, cell = 1, value = " +
wb.getSheetAt(0).getRow(8).getCell(1).toString());
logger.debug("row = 9, cell = 1, value = " +
wb.getSheetAt(0).getRow(9).getCell(1).toString());
==Standard Output==
rowIterator()
row = 0, cell = 1, value = ADDR
row = 1, cell = 1, value = 1220 STATE CAPITOL
row = 2, cell = 1, value = 121 S 3RD ST
row = 3, cell = 1, value = 1419 ADAMS BLVD
row = 4, cell = 1, value = 408 NORFOLK AVE
row = 5, cell = 1, value = 704 PROSPECT AVE
row = 6, cell = 1, value = U S HWY 30 WEST
row = 7, cell = 1, value = 1600 GREAT PLAINS CENTRE
row = 8, cell = 1, value = 1623 HARNEY ST
getRow()
row = 0, cell = 1, value = ADDR
row = 1, cell = 1, value = null; throws NullPointerException
row = 2, cell = 1, value = 1220 STATE CAPITOL
row = 3, cell = 1, value = 121 S 3RD ST
row = 4, cell = 1, value = 1419 ADAMS BLVD
row = 5, cell = 1, value = 408 NORFOLK AVE
row = 6, cell = 1, value = 704 PROSPECT AVE
row = 7, cell = 1, value = U S HWY 30 WEST
row = 8, cell = 1, value = 1600 GREAT PLAINS CENTRE
row = 9, cell = 1, value = 1623 HARNEY ST
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]