If you want to work with xlsx, you'll have to use the org.apache.poi.ss
package. This package has class XSSF, which can be used for parsing xlxs file. This Sample code works on Excel 2007 or later (.xlsx)
OPCPackage pkg = OPCPackage.open(new ByteArrayInputStream(data));
Workbook wb = new XSSFWorkbook(pkg);
Sheet sheet = wb.getSheetAt(0);
Iterator<Row> rows = sheet.rowIterator();
while (rows.hasNext()) {
int j = 5;
Person person= new Person ();
Row row = rows.next();
if (row.getRowNum() > 0) {
person.setPersonId((int)(row.getCell(0).getNumericCellValue()));
person.setFirstName(row.getCell(1).getStringCellValue());
person.setLastName(row.getCell(2).getStringCellValue());
person.setGroupId((int)(row.getCell(3).getNumericCellValue()));
person.setUserName(row.getCell(4).getStringCellValue());
person.setCreditId((int)(row.getCell(5).getNumericCellValue()));
}
}
Excel 1998-2003 file (.xls) - you may use HSSF library.
just use : Workbook wb = new HSSFWorkbook(pkg);