BUG:
While i was trying to read uploaded excel by apache poi (HSSFWorkbook) i got following error:
Error: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML.
You are calling the part of POI that deals with OLE2 Office Documents.
You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
FIX:
The error is taken only with the older .xls (binary) files.
For both .xls and .xlsx files you can use WorkbookFactory. Download poi-ooxml-3.9.jar and add it to classpath.
Workbook workbook = WorkbookFactory.create(new FileInputStream("E:/Code.xlsx"));
Sheet firstSheet = workbook .getSheetAt(0);
Iterator<Row> rowIter = firstSheet.rowIterator();
while(rowIter.hasNext()) {
Object row = rowIter.next();
Iterator<Cell> cellIterator = ((Row) row).cellIterator();
}
No comments:
Post a Comment