gpt4 book ai didi

java - org.apache.poi 中缺少 ENUM

转载 作者:行者123 更新时间:2023-12-01 16:46:48 24 4
gpt4 key购买 nike

我正在尝试使用 org.apache.poi 进行 xls/xlsx 处理。(Springboot)

我遇到异常:

Caused by: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/FileMagic
at org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipStream(ZipHelper.java:208)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:98)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:295)
at ua.siemens.dbtool.service.impl.ExcelServiceImpl.getTemplate(ExcelServiceImpl.java:159)
at ua.siemens.dbtool.service.impl.ExcelServiceImpl.exportTimesheet(ExcelServiceImpl.java:69)
at ua.siemens.dbtool.controller.TimesheetController.exportTimesheet(TimesheetController.java:126)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
... 89 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.poi.poifs.filesystem.FileMagic
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 108 common frames omitted

方法:

private XSSFWorkbook getTemplate() throws IOException, InvalidFormatException {

ClassLoader classLoader = getClass().getClassLoader();
File xlsTemplate = new File(classLoader.getResource(XLS_TEMPLATE).getFile());

return new XSSFWorkbook(new FileInputStream(xlsTemplate));
}

在我的pom.xml中:

<!--EXCEL-->
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>

我在org.apache.poi.poifs.filesystem包中找不到FileMagic,我不知道为什么它不在那里。文档说它必须在那里:link

最佳答案

问题似乎是 poi 版本 3.9 中不存在 FileMagic。

使用版本3.17

    <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>

应该可以解决问题。

此外,为 poipoi-oomxl 使用相同的版本可能是个好主意。

关于java - org.apache.poi 中缺少 ENUM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48990267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com