1

I cant see any mention of how to check if current cell is last row in a spreadsheet in java excel api docs...

When I use code and try to fetch data in next row (after the last row) I get an error-

I can trap this error and hence capture the scenario of having surpassed the last row, however I would like to know if there is some way of directly identifying if a row is the last row in excel sheet, when using java excel api?

For reference, the code that causes this error is given below -- (The exact line that causes the error is the 3rd line in code below)--

//  now go to next value of url in the spreadsheet...
rownum++;
datacell=sheet.getCell((columnread-1), rownum );

For reference, the error I get is --

java.lang.ArrayIndexOutOfBoundsException: 7
 at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)
 at com.arvind.dataentry.Dataentry.process_file(Dataentry.java:245)
Arvind
  • 6,404
  • 20
  • 94
  • 143

1 Answers1

4

You can find the last row with getRows(). It returns the number of rows in the current sheet. With this information you can identify if a given row is the last in a sheet.

See also: http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/jxl/Sheet.html#getRows()

Kai Sternad
  • 22,214
  • 7
  • 47
  • 42
  • `code`Workbook workBook = Workbook.getWorkbook(new File("../xls/data/test.xls")); int sheetNumberOfRows = workBook.getSheet(0).getRows(); int sheetNumberOfColumns = workBook.getSheet(0).getColumns(); System.out.println(sheetNumberOfColumns + "--" + sheetNumberOfRows);`code` – ben.IT Apr 04 '14 at 14:57