The console output is slightly tangled up; data logged to System.err
overlap those logged to System.out
:
java.lang.ArrayIndexOutOfBoundsException: 2
4
2
Name
Value
A
at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)
at SpreadsheetRead.main(SpreadsheetRead.java:25)
1
Let's untangle those, and match them with the respective logging calls:
Error log:
java.lang.ArrayIndexOutOfBoundsException: 2
at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)
at SpreadsheetRead.main(SpreadsheetRead.java:25)
Line 25 is where I am trying to access Cell (2,0)
this indicates that Cell(2,0) is not in the table.
Let's look at the System.out log.
they are also failed it just that I commented those lines when I executed this code.
I assume you mean the access to column 1 and the respective logging calls.
Cell name = sheet.getCell(0, 0);
Cell name1 = sheet.getCell(1, 0);
Cell value = sheet.getCell(0, 1);
Cell value1 = sheet.getCell(1, 1);
System.out.println(sheet.getRows()); //4
System.out.println(sheet.getColumns()); //2
System.out.println(name.getContents()); //Name
System.out.println(name1.getContents()); //Value
System.out.println(value.getContents()); //A
System.out.println(value1.getContents()); //1
Comparing this to the table:
Name Value
A 1
B 2
C 3
indicates that the first argument is the column index, not row index as you seem to expect.
the Sheet#getCell
documentation confirms this:
public Cell getCell(int column, int row)