0

I am trying to read .xlsx file using apache poi3.12, 3.14 is latest and i tried that too.I have included the following jars,

1.poi-3.12-20150511.jar 2.poi-ooxml-3.12-20150511.jar 3.poi-ooxml-schemas-3.12-20150511.jar 4.ooxml-schemas-1.0.jar 5.xmlbeans.2.3.0.jar 6.commons-codec-1.9.jar 7.commons-logging-1.1.3.jar

I am using, jre 1.8_73, as suggested in another question, where he changed from jre 1.8 to jre 1.8_25, it worked for him. But here i am using the latest jre.

the trace:

Exception: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:207)
at readfiles.ReadScsu.readFile(ReadScsu.java:54)
at hello1.hello1.doPost(hello1.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Exception:Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)
... 29 more
`Exception:Caused by: java.lang.ExceptionInInitializerError
at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:44)
... 34 moreCaused by: java.lang.NullPointerException
at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:769)
at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument.<clinit>(Unknown Source)
... 36 more`

im using:

`` try { 


        InputStream   XlsxFileToRead  = this.getClass().getClassLoader()
        .getResourceAsStream("Week2OTSResult.xlsx");


                System.out.println("fs="+XlsxFileToRead.toString() );

                XSSFWorkbook wb = new XSSFWorkbook(XlsxFileToRead);//in debug mode, here is where the exception is caused.


              XSSFSheet sheet = wb.getSheetAt(0);


               System.out.println(sheet.getRow(5).getCell(7).toString());
                    System.out.println("\nin read  file2\n");

    }catch (FileNotFoundException fe)
    { 
           fe.printStackTrace(); 
    } 

    catch (IOException ie)
    { 
        ie.printStackTrace(); 
        } 

1 Answers1

2

It seems that the problem could be related to the version of XMLBeans lib.

It is recommended that XMLBeans 2.6.0 is used with Apache POI, and it is the version now shipped in the binary release packages.

Ilya Patrikeev
  • 352
  • 3
  • 10
  • thank you very much for responding! @leto i Changed it to XMLBeans 2.6.0.jar and still the same problem! – Bhargav. Konare Mar 17 '16 at 18:35
  • I meant i used, XMLBeans 2.6.0.jar too and problems still exists. – Bhargav. Konare Mar 17 '16 at 19:25
  • I can't reproduce the problem with the same set of jars, but the problem definitely relates to jar dependency in your system. I'd recommend to remove ooxml-schemas-1.0.jar from the classpath, and check if it helps. You can read more about this lib and about its necessity in component map section here: https://poi.apache.org/overview.html – Ilya Patrikeev Mar 18 '16 at 10:11