gudii9
asked on
read.xlsx files using apache POI xssfworkbook ie XSSF api
Hi,
I am looking for good examples to read.xlsx files using apache POI xssfworkbook ie XSSF api.
I am getting following error when I try to read .xlsx file usiong HSSF api.
Excel file
org.apache.poi.poifs.files ystem.Offi ceXmlFileE xception: 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.stora ge.HeaderB lock.<init >(HeaderBl ock.java:1 31)
at org.apache.poi.poifs.stora ge.HeaderB lock.<init >(HeaderBl ock.java:1 04)
at org.apache.poi.poifs.files ystem.POIF SFileSyste m.<init>(P OIFSFileSy stem.java: 138)
at Processor2.read(Processor2 .java:55)
at Processor2.main(Processor2 .java:37)
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
I am looking for good examples to read.xlsx files using apache POI xssfworkbook ie XSSF api.
I am getting following error when I try to read .xlsx file usiong HSSF api.
Excel file
org.apache.poi.poifs.files
at org.apache.poi.poifs.stora
at org.apache.poi.poifs.stora
at org.apache.poi.poifs.files
at Processor2.read(Processor2
at Processor2.main(Processor2
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sure
ASKER
now all compilation errors are gone. When I run java application seeing error as
org.apache.poi.poifs.files ystem.Offi ceXmlFileE xception: 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)
Please advise
org.apache.poi.poifs.files
Please advise
ASKER
I tried to read as .xlsx follows
public static Vector readXlsx(String fileName) {
Vector cellVectorHolder = new Vector();
try{
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
XSSFWorkbook myWorkBook = new XSSFWorkbook(myFileSystem)
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
Iterator rowIter = mySheet.rowIterator();
while(rowIter.hasNext()){
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
Vector cellStoreVector=new Vector();
while(cellIter.hasNext()){
HSSFCell myCell = (HSSFCell) cellIter.next();
cellStoreVector.addElement
}
cellVectorHolder.addElemen
}
}catch (Exception e){e.printStackTrace(); }
return cellVectorHolder;
}
I am getting compilation errors as my program not able to read XSSFWorkbook , XSSFSheet for some reason.
I tried to import as well as below
import org.apache.poi.xssf.usermo
import org.apache.poi.xssf.usermo
import org.apache.poi.xssf.usermo
import org.apache.poi.xssf.usermo
My program is not recognizing these imports by giving compilation error. Please advise