JXSL报错CannotOpenWorkbookException和Cannot load XLS transformer解决方案

JXSL报错org.jxls.util.CannotOpenWorkbookException:org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException: No valid entries or contents found, this is not a valid OOXML和Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath解决方案

一、bug简介

在做Excel导出的时候使用jxsl工具导出到Excel模板,后台一直报错,
Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath;或者org.jxls.util.CannotOpenWorkbookException:org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException: No valid entries or contents found, this is not a valid OOXML (Office Open)
错误。

1.1 org.jxls.util.CannotOpenWorkbookException:org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException: No valid entries or contents found, this is not a valid OOXML (Office Open)

可能是因为没有在maven中排出调xlsx文件,导致编译的时候改变了文件。在maven中加入以下配置

<build>
 <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>excelModel/*.xlsx</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <includes>
                    <include>excelModel/*.xlsx</include>
                </includes>
            </resource>
        </resources>
	<plugins>
			<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>
	</plugins>
</build>

excelModel文件夹里面是我存放模板的地方。
我clean之后重新编译,不报这个问题了,开始报错第二个问题。

1.2.Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath

这个错误是由于easypoi版本不匹配,jxsl我引入的是2.0.0版本,需要easypoi的版本为4.X版本。

 <!-- jxls -->
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls</artifactId>
            <version>2.10.0</version>
        </dependency>

        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-poi</artifactId>
            <version>2.10.0</version>
        </dependency>

由于项目本身引入了3.5版本的poi,所以需要先排除4.0版本的poi,然后修改easypoi的3.5版本为4.1.2版本。

 <!-- jxls -->
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls</artifactId>
            <version>2.10.0</version>
        </dependency>

        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-poi</artifactId>
            <version>2.10.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi-ooxml</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
<!--excel操作-->
		<dependency>
			<groupId>cn.afterturn</groupId>
			<artifactId>easypoi-base</artifactId>
			<version>4.1.2</version>
		</dependency>
		<dependency>
			<groupId>cn.afterturn</groupId>
			<artifactId>easypoi-web</artifactId>
			<version>4.1.2</version>
		</dependency>
		<dependency>
			<groupId>cn.afterturn</groupId>
			<artifactId>easypoi-annotation</artifactId>
			<version>4.1.2</version>
		</dependency>

至此,问题解决。

参考博客:

[1].https://www.freesion.com/article/9144783384/
[2]: https://stackoverflow.com/questions/39754573/cannot-load-xls-transformer-please-make-sure-a-transformer-implementation-is-in

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值