gudii9
asked on
apache POI excel 2007 reading examples
Hi,
I am looking for good examples on how to read.xlsx files using apache POI
I am getting error as follows when I try to read it
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)
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
I am looking for good examples on how to read.xlsx files using apache POI
I am getting error as follows when I try to read it
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)
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The page is full of links to source code
Attached is a modified code from:
http://www.coderanch.com/t/424181/open-source/Read-xls-xlsx-file-format
The sample is reading XLSX
Tested with: poi-3.7
XLSX2CSV.java
http://www.coderanch.com/t/424181/open-source/Read-xls-xlsx-file-format
The sample is reading XLSX
Tested with: poi-3.7
XLSX2CSV.java
ASKER
i tried the example getting error like
Exception in thread "main" java.lang.NoClassDefFoundE rror: org/dom4j/DocumentExceptio n
at org.apache.poi.openxml4j.o pc.OPCPack age.init(O PCPackage. java:154)
at org.apache.poi.openxml4j.o pc.OPCPack age.<init> (OPCPackag e.java:141 )
at org.apache.poi.openxml4j.o pc.Package .<init>(Pa ckage.java :54)
at org.apache.poi.openxml4j.o pc.ZipPack age.<init> (ZipPackag e.java:99)
at org.apache.poi.openxml4j.o pc.OPCPack age.open(O PCPackage. java:207)
at com.aaa.XLSX2CSV.main(XLSX 2CSV.java: 392)
Caused by: java.lang.ClassNotFoundExc eption: org.dom4j.DocumentExceptio n
at java.net.URLClassLoader$1. run(URLCla ssLoader.j ava:202)
Please advbise
Exception in thread "main" java.lang.NoClassDefFoundE
at org.apache.poi.openxml4j.o
at org.apache.poi.openxml4j.o
at org.apache.poi.openxml4j.o
at org.apache.poi.openxml4j.o
at org.apache.poi.openxml4j.o
at com.aaa.XLSX2CSV.main(XLSX
Caused by: java.lang.ClassNotFoundExc
at java.net.URLClassLoader$1.
Please advbise
ASKER
i put dom4j 1.4 jar and
xmlbeans 2.2.0 jar
now i am seeing errror like
Exception in thread "main" java.lang.ExceptionInIniti alizerErro r
at sun.misc.Unsafe.ensureClas sInitializ ed(Native Method)
at sun.reflect.UnsafeFieldAcc essorFacto ry.newFiel dAccessor( UnsafeFiel dAccessorF actory.jav a:25)
at sun.reflect.ReflectionFact ory.newFie ldAccessor (Reflectio nFactory.j ava:122)
at java.lang.reflect.Field.ac quireField Accessor(F ield.java: 918)
at java.lang.reflect.Field.ge tFieldAcce ssor(Field .java:899)
at java.lang.reflect.Field.ge t(Field.ja va:358)
at org.apache.xmlbeans.XmlBea ns.typeSys temForClas sLoader(Xm lBeans.jav a:770)
at org.openxmlformats.schemas .spreadshe etml.x2006 .main.Styl eSheetDocu ment.<clin it>(Unknow n Source)
at org.openxmlformats.schemas .spreadshe etml.x2006 .main.Styl eSheetDocu ment$Facto ry.parse(U nknown Source)
at org.apache.poi.xssf.model. StylesTabl e.readFrom (StylesTab le.java:12 1)
at org.apache.poi.xssf.model. StylesTabl e.<init>(S tylesTable .java:92)
at org.apache.poi.xssf.eventu sermodel.X SSFReader. getStylesT able(XSSFR eader.java :90)
at com.aa.XLSX2CSV.process(XL SX2CSV.jav a:358)
at com.aaa.XLSX2CSV.main(XLSX 2CSV.java: 394)
Caused by: java.lang.RuntimeException : Could not instantiate SchemaTypeSystemImpl (java.lang.reflect.Invocat ionTargetE xception): is the version of xbean.jar correct?
at schemaorg_apache_xmlbeans. system.sE1 30CAA0A01A 7CDE5A2B4F EB8B311707 .TypeSyste mHolder.lo adTypeSyst em(Unknown Source)
at schemaorg_apache_xmlbeans. system.sE1 30CAA0A01A 7CDE5A2B4F EB8B311707 .TypeSyste mHolder.<c linit>(Unk nown Source)
... 14 more
Caused by: java.lang.reflect.Invocati onTargetEx ception
at sun.reflect.NativeConstruc torAccesso rImpl.newI nstance0(N ative Method)
at sun.reflect.NativeConstruc torAccesso rImpl.newI nstance(Na tiveConstr uctorAcces sorImpl.ja va:39)
at sun.reflect.DelegatingCons tructorAcc essorImpl. newInstanc e(Delegati ngConstruc torAccesso rImpl.java :27)
at java.lang.reflect.Construc tor.newIns tance(Cons tructor.ja va:513)
... 16 more
Caused by: org.apache.xmlbeans.Schema TypeLoader Exception: XML-BEANS compiled schema: Incompatible minor version - expecting up to 23, got 24 (schemaorg_apache_xmlbeans .system.sE 130CAA0A01 A7CDE5A2B4 FEB8B31170 7.index) - code 3
at org.apache.xmlbeans.impl.s chema.Sche maTypeSyst emImpl$Xsb Reader.<in it>(Schema TypeSystem Impl.java: 1522)
at org.apache.xmlbeans.impl.s chema.Sche maTypeSyst emImpl.ini tFromHeade r(SchemaTy peSystemIm pl.java:26 0)
at org.apache.xmlbeans.impl.s chema.Sche maTypeSyst emImpl.<in it>(Schema TypeSystem Impl.java: 183)
... 20 more
xmlbeans 2.2.0 jar
now i am seeing errror like
Exception in thread "main" java.lang.ExceptionInIniti
at sun.misc.Unsafe.ensureClas
at sun.reflect.UnsafeFieldAcc
at sun.reflect.ReflectionFact
at java.lang.reflect.Field.ac
at java.lang.reflect.Field.ge
at java.lang.reflect.Field.ge
at org.apache.xmlbeans.XmlBea
at org.openxmlformats.schemas
at org.openxmlformats.schemas
at org.apache.poi.xssf.model.
at org.apache.poi.xssf.model.
at org.apache.poi.xssf.eventu
at com.aa.XLSX2CSV.process(XL
at com.aaa.XLSX2CSV.main(XLSX
Caused by: java.lang.RuntimeException
at schemaorg_apache_xmlbeans.
at schemaorg_apache_xmlbeans.
... 14 more
Caused by: java.lang.reflect.Invocati
at sun.reflect.NativeConstruc
at sun.reflect.NativeConstruc
at sun.reflect.DelegatingCons
at java.lang.reflect.Construc
... 16 more
Caused by: org.apache.xmlbeans.Schema
at org.apache.xmlbeans.impl.s
at org.apache.xmlbeans.impl.s
at org.apache.xmlbeans.impl.s
... 20 more
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i used below jars from poi distribution:
...
xmlbeans-2.3.0.jar
i put dom4j 1.4 jar andWhich is it?
xmlbeans 2.2.0 jar
now i am seeing errror like
...
at com.aaa.XLSX2CSV.main(XLSX2CSV.java: 394)
Caused by: java.lang.RuntimeException: Could not instantiate SchemaTypeSystemImpl (java.lang.reflect.Invocat ionTargetE xception): is the version of xbean.jar correct?
ASKER
putting both xmlbean and xbean same version solved issue like
xmlbeans-2.3.0.jar
and
xbean2.3 jar
xmlbeans-2.3.0.jar
and
xbean2.3 jar
So it's ok then?
It's got to be said that's it's almost laughable to have to use these complex apis to read what's essentially a 2 column csv file ;)
It's got to be said that's it's almost laughable to have to use these complex apis to read what's essentially a 2 column csv file ;)
ASKER