I need help reading xls files using apache XSSF.
The implementation of XSSF is working fine for "xlsx". Not working for "xls" files.
Here is the code:
XSSFWorkbook workBook = new XSSFWorkbook("fileName");
XSSFSheet sheet = workBook.getSheetAt(0);
XSSFRow row = sheet.getRow(0);
Any workaround is appreciated.
XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (. xlsx) file format. HSSF and XSSF provides ways to read spreadsheets create, modify, read and write XLS spreadsheets.
Apache POI is your Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and OLE2 formats and welcome others to participate. OLE2 files include most Microsoft Office files such as XLS, DOC, and PPT as well as MFC serialization API based file formats.
Rather than using XSSF classes directly, you should use the interfaces that are common between both HSSF (.xls) and XSSF (.xlsx). The snippet of code from your question would then become:
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 the Apache POI QuickGuide for more information and examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With