Bug 48598 - code migration problem
Summary: code migration problem
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2010-01-22 01:30 UTC by satish
Modified: 2010-01-22 02:23 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description satish 2010-01-22 01:30:42 UTC
We are using poi3.0.2.jar file.

where the code(attached) works fine for xls files

Sheet sheet = wb.getSheetAt(0);
Row row;
Cell cell;
for(int r = 0; r < rows; r++) {
	row = sheet.getRow(r);
	if(row != null) {
	for(int c = -1; c < cols; c++) {
	cell = row.getCell((short)c);

where as if I  pass xlsx files its giving followig error.

java.lang.IllegalArgumentException: Cell index must be >= 0
	at org.apache.poi.xssf.usermodel.XSSFRow.getCell(XSSFRow.java:191)
	at org.apache.poi.xssf.usermodel.XSSFRow.getCell(XSSFRow.java:178)
	at org.apache.poi.xssf.usermodel.XSSFRow.getCell(XSSFRow.java:35)
	at ReadExcel.readBoth(ReadExcel.java:190)
	at ReadExcel.main(ReadExcel.java:39)

The problem is with row.getCell(-1)
this method returns null in POI3.0.2
the same method throws IllegalArgumentException in POI3.5

So we need to change the code?
Comment 1 Nick Burch 2010-01-22 02:23:04 UTC
row.getCell(-1) is not a valid thing to ask for

As the error message tells you, cells start at 0. Either ask for cells from 0 onwards, or use an iterator.