首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jxls错误:无法加载XLS转换器。请确保Transformer实现位于类路径中

Jxls错误:无法加载XLS转换器。请确保Transformer实现位于类路径中
EN

Stack Overflow用户
提问于 2016-03-11 00:24:17
回答 6查看 8.9K关注 0票数 6

这个问题已经被提出过一次,但没有人给出一个绝对的解决方案。我试图从一个现有的模板生成一个xls文件,但我得到了一个错误,我不知道如何面对!

我的代码: String nombre = "Manuel";

代码语言:javascript
复制
        try (InputStream templateFileName = ExportExcelServlet.class.getResourceAsStream("/segJBOSS/lib/xls/Tabla_Gestion.xlsx")) {
            try (OutputStream destFileName = new FileOutputStream("Tabla_Gestion.xls")) {
                ArrayList<String> array = new ArrayList<String>();
                array.add(nombre);
                Context context = new Context();
                context.putVar("gestion", array);
                JxlsHelper.getInstance().processTemplate(templateFileName, destFileName, context);              
                } catch (Exception e) {
                // TODO: handle exception
                System.out.println(e.getMessage());
                e.printStackTrace();                
                }

        } catch (Exception e) {
            // TODO: handle exception
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    } catch (Exception e) {
        // TODO: handle exception
        System.out.println(e.getMessage());
        e.printStackTrace();
    }

这将在WebServlet中实现。

代码语言:javascript
复制
17:08:43,472 ERROR [org.jxls.util.TransformerFactory] (default task-3) Method createTransformer of org.jxls.transform.poi.PoiTransformer class thrown an Exception: java.lang.reflect.InvocationTargetException

Caused by: java.lang.NullPointerException

17:08:43,478 INFO  [stdout] (default task-3) Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath
17:08:43,479 ERROR [stderr] (default task-3) java.lang.IllegalStateException: Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath

非常感谢!

EN

回答 6

Stack Overflow用户

发布于 2016-03-11 04:50:50

请确保类路径中有jxls-poi和Apache POI jars (如果您计划使用Apache POI)

票数 2
EN

Stack Overflow用户

发布于 2018-06-29 16:06:36

在我的例子中,我的类路径中有不兼容的apache poi版本。jxls-poi:1.0.15使用poi:3.17,而我使用poi:3.9

将poi更改为3.17修复了我的问题。

票数 1
EN

Stack Overflow用户

发布于 2017-09-06 15:33:53

好的,如果你使用maven,当maven构建时,maven可能会破坏excel文件。

JXLS报告的异常可能是模棱两可的,它实际上是在创建一个excel文件异常。

你可以这样做:

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35921928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档