我一直在尝试使上传(在旧的网络应用程序中)兼容 xls 和 xlsx 文件,xls 运行良好,但上传 xlsx 会引发此错误:
SEVERE: Servlet.service() for servlet [MainServlet] in context with path [/timesheet] threw exception [Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError: org.apache.crimson.tree.ElementNode2.getTextContent()Ljava/lang/String;
at org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.readElement(PackagePropertiesUnmarshaller.java:146)
at org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.loadCreated(PackagePropertiesUnmarshaller.java:162)
at org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.unmarshall(PackagePropertiesUnmarshaller.java:124)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:788)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:327)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:185)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:144)
当前的 poi lib 版本是 3.14,但我也尝试过 3.16(相同错误)和 3.17,该应用程序当前使用的是 Java 1.6
public List<AttendanceRecord> getAttendanceRecords(List<AttendanceRecordErrMsg> errorMessages) throws Exception {
Workbook wb = WorkbookFactory.create(new FileInputStream(arFile)); //app already throws an error upon reaching this line
List<AttendanceRecord> attendanceRecordList = new ArrayList<AttendanceRecord>();
出现这种错误的原因是因为你的项目中包含了Crimson Library,它只提供了接口上的实现(基于xml-apis 1.0.b2,最新版本1.1.3)Node
,并没有实现getTextContent()
根据Document引入的方法对象模型 (DOM) 级别 3 核心规范。
要修复此类错误,您可以执行以下操作之一:
1.从您的项目中删除Crimson 库。
2.通过添加以下行javax.xml.parsers.DocumentBuilderFactory
来指定系统属性以避免使用org.apache.crimson.jaxp.DocumentBuilderFactoryImpl
类
System.setProperty("javax.xml.parsers.DocumentBuilderFactory","com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句