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)

1 Answer 1

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()

Sign up to request clarification or add additional context in comments.

1 Comment

codeWorkbook 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.