Ok guys, I'm a recent intern (very newbie) at a company and the first task
they gave me is to change a code that reads only .xls files using HSSF to
work with both new and old versions of Excel. So, I downloaded the new
.jars, updated the code and migrated to SS, but unfortunately it won't open
.xlsx (while .xls does fine).
Code:
Workbook oWorkgroup;
m_oFileName = oFileToLoad;
try {
//LOG.Log("ExcelFile - Loading file name: " +
m_oFileName.getPath(), LOG.LOG_TYPE_TRACE);
m_oIn = new FileInputStream(m_oFileName.getPath());
oWorkgroup = WorkbookFactory.create(m_oIn);
Errors:
[java] org.apache.poi.POIXMLException:
java.lang.reflect.InvocationTargetException
[java] at
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:61)
[java] at
org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:256)
[java] at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:196)
[java] at
org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:172)
[java] at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:63)
[java] at com.msights.core.utils.ExcelFile.loadFile(ExcelFile.java:76)
[java] at
com.msights.core.utils.GroupLoader.loadFiles(GroupLoader.java:50)
[java] at test.TestClient.main(TestClient.java:136)
[java] Caused by: java.lang.reflect.InvocationTargetException
[java] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
[java] at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[java] at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[java] at
java.lang.reflect.Constructor.newInstance(Constructor.java:494)
[java] at
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:59)
[java] ... 7 more
[java] Caused by: java.lang.ExceptionInInitializerError
[java] at sun.misc.Unsafe.ensureClassInitialized(Native Method)
[java] at
sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25)
[java] at
sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122)
[java] at java.lang.reflect.Field.acquireFieldAccessor(Field.java:917)
[java] at java.lang.reflect.Field.getFieldAccessor(Field.java:898)
[java] at java.lang.reflect.Field.get(Field.java:357)
[java] at
org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:770)
[java] at
org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument.<clinit>(Unknown
Source)
[java] at
org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument$Factory.parse(Unknown
Source)
[java] at
org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:102)
[java] at
org.apache.poi.xssf.model.StylesTable.<init>(StylesTable.java:91)
[java] ... 12 more
[java] Caused by: java.lang.RuntimeException: Could not instantiate
SchemaTypeSystemImpl (java.lang.reflect.InvocationTargetException): is the
version of xbean.jar correct?
[java] at
schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.TypeSystemHolder.loadTypeSystem(Unknown
Source)
[java] at
schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.TypeSystemHolder.<clinit>(Unknown
Source)
[java] ... 23 more
[java] Caused by: java.lang.reflect.InvocationTargetException
[java] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
[java] at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[java] at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[java] at
java.lang.reflect.Constructor.newInstance(Constructor.java:494)
[java] ... 25 more
[java] Caused by: org.apache.xmlbeans.SchemaTypeLoaderException:
XML-BEANS compiled schema: Incompatible minor version - expecting up to 23,
got 24
(schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.index) -
code 3
[java] at
org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl$XsbReader.<init>(SchemaTypeSystemImpl.java:1522)
[java] at
org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.initFromHeader(SchemaTypeSystemImpl.java:260)
[java] at
org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:183)
[java] ... 29 more
Any idea of what's going on? Thank you.