简体   繁体   English

使用apache poi读取.xlsx文件在linux机器上给出了org.apache.poi.POIXMLException

[英]Reading .xlsx file using apache poi gives org.apache.poi.POIXMLException on linux machine

I have an application which reads an .xlsx file and displays the content to the user. 我有一个应用程序,它读取.xlsx文件并向用户显示内容。 The application works fine on a windows environment. 该应用程序在Windows环境中正常工作。

I deployed the .war file of this web app on tomcat6 on a ubuntu server. 我在ubuntu服务器上的tomcat6上部署了此Web应用程序的.war文件。 I also copied the .xlsx files on the server. 我还复制了服务器上的.xlsx文件。

The path of the files in the code is correct. 代码中文件的路径是正确的。

But the line 但行

FileInputStream file = new FileInputStream(new File(FileName));
XSSFWorkbook workbook = new XSSFWorkbook(file);

gives an error 给出错误

java.lang.reflect.InvocationTargetException
org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:207)
com.qm.action.GetProjectNames.execute(GetProjectNames.java:107)

I have checked that the variable FileName contains the correct path and filename of the files on server(/usr/local/Metrics/MetricFiles/FY2013_Q2_GIT_Review_Metrics_by_LSS-GC.xlsx) 我检查过变量FileName包含服务器上文件的正确路径和文件名(/usr/local/Metrics/MetricFiles/FY2013_Q2_GIT_Review_Metrics_by_LSS-GC.xlsx)

Since the ubunut server is a VM, I had copied the .xlsx files using WinSCP. 由于ubunut服务器是VM,我使用WinSCP复制了.xlsx文件。 The size of the files is also correct. 文件的大小也是正确的。

Why is this error occurring on linux platform? 为什么这个错误发生在linux平台上?

Adding the Additional exception trace 添加附加异常跟踪

Caused by: java.lang.reflect.InvocationTargetException at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at 
java.lang.reflect.Constructor.newInstance(Constructor.java:525) at 
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60) ... 68 more 
Caused by: java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange(Arrays.java:2694) at java.lang.String.<init>(String.java:203) at 
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseCdataLiteral(PiccoloLexer.java:3027) at 
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseQuotedTagValue(PiccoloLexer.java:2936) at 
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseAttributesNS(PiccoloLexer.java:1754) at 
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseOpenTagNS(PiccoloLexer.java:1521) at 
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseTagNS(PiccoloLexer.java:1362) at 
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.yylex(PiccoloLexer.java:4678) at 
org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yylex(Piccolo.java:1290) at 
org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yyparse(Piccolo.java:1400) at 
org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:714) at 
org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3439) at 
org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1270) at 
org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1257) at 
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345) at 
org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument$Factory.parse(Unknown Source) at 
org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:121) at 
org.apache.poi.xssf.model.StylesTable.<init>(StylesTable.java:92) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at 
java.lang.reflect.Constructor.newInstance(Constructor.java:525) at 
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60) 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 
com.qm.action.GetProjectNames.execute(GetProjectNames.java:107) at 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at 
java.lang.reflect.Method.invoke(Method.java:601) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)

Promoting a comment to an answer... 推荐评论答案......

The key part of your stacktrace, which explains what has broken and why, is: stacktrace的关键部分是:它解释了什么已破坏以及原因:

Caused by: java.lang.OutOfMemoryError: Java heap space at 
java.util.Arrays.copyOfRange(Arrays.java:2694)

This is telling us that Java didn't have enough memory allocated to it to store all of the data that processing your file entails 这告诉我们Java没有足够的内存分配给它来存储处理文件所需的所有数据

If you need help with increasing your JVM heap size, I would suggest you review this previous question or this one , which both talk you through it all. 如果您在增加JVM堆大小方面需要帮助,我建议您查看以前的问题或者这个 问题 ,它们都会引导您完成所有问题。

I was also getting same exception when reading .xlsx file 在阅读.xlsx文件时,我也遇到了同样的异常

org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
Caused By :java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlBeans.typeSystemForClassLoadern

Then I"ve removed my old xmlbeans-2.0.jar and put the latest xmlbeans-2.3.0.jar containing this method and it is solved now 然后我删除了我的旧xmlbeans-2.0.jar并放入了包含此方法的最新xmlbeans-2.3.0.jar ,现在解决了

I have inserted org.apache.xmlbeans in in project. 我在项目中插入了org.apache.xmlbeans It helped. 它有所帮助。

Like the others answers: add this dependency: 像其他答案一样:添加此依赖项:

<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>2.6.0</version>
</dependency>

It will work after that. 它会在那之后起作用。

In fact poi-ooxml needs poi and poi-ooxml-schemas but poi-ooxml-schemas needs xmlbeans 事实上,poi-ooxml需要poi和poi-ooxml-schemas,但poi-ooxml-schemas需要xmlbeans

You can see these prerequisites at this page https://poi.apache.org/overview.html 您可以在此页面https://poi.apache.org/overview.html上查看这些先决条件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“ main”中的异常org.apache.poi.POIXMLException使用apache POI从xlsx文件读取数据时出现异常 - Exception in thread “main” org.apache.poi.POIXMLException exception appearing while reading data from xlsx file using apache POI org.apache.poi.POIXMLException:org.apache.poi.openxml4j.exceptions.InvalidFormatException: - org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: org.apache.poi.POIXMLException:使用Libre Office更新.xls文件后POI API中的java.lang.reflect.InvocationTargetException - org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException in POI API after an .xls file is updated with Libre Office org.apache.poi.POIXMLException 目前不支持严格的 OOXML,请参阅错误 #57699 - org.apache.poi.POIXMLException Strict OOXML isn't currently supported, please see bug #57699 ApachePOI生成org.apache.poi.POIXMLException:java.lang.reflect.InvocationTargetException - ApachePOI generates org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException 使用 Apache POI 读取.xlsx 文件给出 InvocationTargetException - Reading .xlsx file using Apache POI gives InvocationTargetException org.apache.poi.POIXMLException:java.lang.reflect.InvocationTargetException,根本原因是空指针异常(xmlbeans.jar) - org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException,root cause nullpointer exception(xmlbeans.jar) 使用Apache POI读取xlsx文件时出现异常(org.apache.poi.openxml4j.exceptions.InvalidFormatException:日期格式不正确,…)? - Exception(org.apache.poi.openxml4j.exceptions.InvalidFormatException: Date not well formated, …) when reading xlsx file using Apache POI? Apache POI 在 Linux 环境下读取 xlsx 文件时抛出异常 - Apache POI throws exception while reading xlsx file in Linux enviroment 使用Apache POI将工作表追加到Excel文件中-NullPointerException导致POIXMLException - Appending a sheet to an Excel file using Apache POI - POIXMLException caused by NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM