Reputation: 1
I try to read the Excel sheet which is old format using jxl jar, it works fine but after 255 row it throws error :
java.lang.ArrayIndexOutOfBoundsException: 255
I cant read with Poi jar
because of it is in old format, Any help much appreciated!
Below is java code snippet given below:
public HashMap<String, Float> readAllRowsOnePoint(String path, String sheetname) throws BiffException, IOException {
System.out.println("Path download" + path);
FileInputStream fs = new FileInputStream(path);
Workbook wb = Workbook.getWorkbook(fs);
Sheet sheet = wb.getSheet(sheetname);
// To get the number of rows present in sheet
int totalNoOfRows = 500;
System.out.println("The rows count is " + totalNoOfRows);
HashMap<String, Float> map = new HashMap<>();
for (int row = 2; row < totalNoOfRows; row++) {
try {
Cell dateCell = null;
Cell psidCell = null;
Cell nameCell = null;
Cell quantityCell = null;
Cell billingCell = null;
try {
dateCell = sheet.getCell(0, row);
psidCell = sheet.getCell(1, row);
nameCell = sheet.getCell(2, row);
quantityCell = sheet.getCell(8, row);
billingCell = sheet.getCell(10, row);
} catch(Exception e){
// e.printStackTrace();
}
String date = dateCell.getContents().trim();
String psid = psidCell.getContents().trim();
String name = nameCell.getContents().trim();
String quantity = quantityCell.getContents().trim();
String billing = billingCell.getContents().trim();
System.out.println();
} catch(Exception e) {
System.out.println("Error in row " + row + " Exception " );
}
}
return map;
}
Upvotes: 0
Views: 927
Reputation: 22343
Your problem is on this line:
for (int i = 0 ; i < 1000; i++)
You can't just insert 1000
because you don't know if every sheet has 1000 rows. Just use the getRows()
method from the Sheet
object(As it already shows in the comment above the line):
for (int i = 0 ; i < s.getRows(); i++)
That way you can't receive an ArrayIndexOutOfBoundsException because the loop stops after all rows are done.
Upvotes: 1