Instead of using the XSSF classes directly, you should use interfaces that are common between HSSF (.xls) and XSSF (.xlsx). Then the code snippet from your question will become as follows:
Workbook wb = WorkbookFactory.create(file); // Or InputStream
Sheet sheet = workBook.getSheetAt(0);
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
System.out.println("Cell A1 is of type " + cell.getCellType());
See Apache POI QuickGuide for more information and examples .
source
share