I am trying to read from an excel file using the below code:
File file = new File("/C:/behzad-data/trp.small.xlsx");
String dataPath=file.getAbsolutePath();
System.out.println(dataPath);
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
//XSSFWorkbook wb = new XSSFWorkbook(file);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row;
HSSFCell cell;
but it complains with:
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)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:152)
so i have seen this, and make it like
XSSFWorkbook wb = new XSSFWorkbook(file);
// HSSFWorkbook wb = new HSSFWorkbook(fs);
but it complains with:
Type mismatch: cannot convert from XSSFSheet to HSSFSheet
How can i resolve both errors at the same time?