gpt4 book ai didi

java - 无法加载 XLS 变压器。请确保 Transformer 实现位于类路径中

转载 作者:行者123 更新时间:2023-12-01 09:27:01 27 4
gpt4 key购买 nike

早上好,我正在尝试复制此内容:http://jxls.sourceforge.net/getting_started.html

使用我自己的集体诉讼而不是员工。但我有一些问题。

这是我的代码:

package src;

import java.util.List;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.LocalTime;
import java.util.ArrayList;


import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public class Excel {

public static void main(String[] args)throws IOException, InterruptedException{

String srcFilePath = "C:/Users/BKLYN/workspace/GenerateABSValues/action_template.xls";
String destFilePath = "C:/Users/BKLYN/workspace/GenerateABSValues/actionCour.xls";

LocalTime time = LocalTime.now();

Logger logger = LoggerFactory.getLogger(Excel.class);
logger.info("Test Action");

//List<action> listAction = generateData(time);


try(InputStream is = Excel.class.getResourceAsStream(srcFilePath)) {
try (OutputStream os = new FileOutputStream(destFilePath)) {
List<action> listAction = generateData(time);
Context context = new Context();
context.putVar("action", listAction);
JxlsHelper.getInstance().processTemplate(is, os, context);
System.out.println("5");

}catch (Exception e){
e.printStackTrace();
}
}catch (Exception e){
e.printStackTrace();
}


}



private static List<action> generateData(LocalTime time){

List<action> listAction = new ArrayList<>();
for (int i =0; i<10; i++){
listAction.add(new action("AB SCIENCE", time, i));
System.out.println("name=" + "AB SCIENCE" + " time= " + time + " Value= " + i);
}
return listAction;
}


}

我为教程的员工生成行动值(value)。

我将这些 jar 文件添加到我的项目中:asm-3.3.1.jar -
cglib-2.2.2.jar -commons-beanutils-1.9.2.jar -commons-codec-1.9.jar -commons-collections-3.2.1.jar -commons-digester3-3.2-with-deps.jar -commons-jexl-2.1.1.jar -commons-logging-1.1.1.jar -jcl-over-slf4j-1.7.12.jar -jxl-2.6.10.jar -log4j-1.2.14.jar -logback-classic-1.1.3.jar -logback-core-1.1.3.jar -poi-3.12.jar -poi-ooxml-3.12.jar -poi-ooxml-schemas-3.12.jar -slf4j-api-1.7.12.jar -stax-api-1.0.1.jar -xmlbeans-2.6.0.jar -jxls-2.3.0.jar -jxls-jexcel-1.0.6.jar -jxls-poi-1.0.9.jar -jxls-reader-2.0.2.jar -

当我尝试运行该项目时,我得到了这个:

19:38:14.601 [main] DEBUG org.jxls.util.TransformerFactory - Transformer class is org.jxls.transform.poi.PoiTransformer
19:38:14.608 [main] ERROR org.jxls.util.TransformerFactory - Method createTransformer of org.jxls.transform.poi.PoiTransformer class thrown an Exception
java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~ [na:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_91]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_91]
at org.jxls.util.TransformerFactory.createTransformer(TransformerFactory.java:35) ~[jxls-2.3.0.jar:na]
at org.jxls.util.JxlsHelper.createTransformer(JxlsHelper.java:202) [jxls-2.3.0.jar:na]
at org.jxls.util.JxlsHelper.processTemplate(JxlsHelper.java:93) [jxls-2.3.0.jar:na]
at src.Excel.main(Excel.java:43) [classes/:na]
Caused by: java.lang.NullPointerException: null
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:162) ~[poi-ooxml-3.12.jar:3.12]
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:143) ~[poi-ooxml-3.12.jar:3.12]
at org.jxls.transform.poi.PoiTransformer.createTransformer(PoiTransformer.java:49) ~[jxls-poi-1.0.9.jar:na]
at org.jxls.transform.poi.PoiTransformer.createTransformer(PoiTransformer.java:42) ~[jxls-poi-1.0.9.jar:na]
... 8 common frames omitted


java.lang.IllegalStateException: Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath
at org.jxls.util.JxlsHelper.createTransformer(JxlsHelper.java:204)
at org.jxls.util.JxlsHelper.processTemplate(JxlsHelper.java:93)
at src.Excel.main(Excel.java:43)

以及我现在拥有的依赖项:

 <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-poi</artifactId>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-jexcel</artifactId>
<version>1.0.6</version>
</dependency>
</dependencies>

我尝试向依赖项添加许多不同的东西,但没有任何改变。我使用 Maven > 更新项目更新了项目。这是最糟糕的。我多次重新创建项目以正确添加 jar 以避免冲突。我知道其他人已经问过这个问题,但我找不到正确的答案。

我不太擅长使用java,所以也许错误很明显。缺少的文件是什么以及在哪里/如何添加它?

谢谢。

最佳答案

如果你使用maven,maven可以在构建时破坏excel文件。

JXLS 报告的异常可能不明确,它实际上是创建一个 excel 文件异常。

你可以这样做:

 <resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
<excludes>
<exclude>template/*.*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/</directory>
<filtering>false</filtering>
<includes>
<include>template/*.*</include>
</includes>
</resource>
</resources>

关于java - 无法加载 XLS 变压器。请确保 Transformer 实现位于类路径中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39754573/

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