当前位置:   article > 正文

解决easyexcel的poi版本冲突_easyexcel版本

easyexcel版本

        项目有需求需要支持excel导入导出功能,导出有个组员先做了,但是他用的是低版本的poi。后面让我来做导入功能,我用的easyexcel来做,easyexel的poi版本又比较高。导致poi版本不一致造成了冲突,又因为导出是基于引入的平台jar做的,他那边也不想改源码,就只有我自己搞了。

        网上搜了很多方法都不管用,最后还是靠大佬说的直接改easyexcel源码中的依赖,将poi依赖jar改成自定义的jar路径,就不会涉及到会导成其他版本poi的bug了。但是美中不足的是大佬们都是授人以渔的,没有现成的文件(虽然说工具都提供了)。在自己试错了很多次后终于搞出来了一个自用版本的easyexcel。也就供大家下载吧。(但是因为最近太忙了,时间也有点久远,可能有的说法或步骤有问题,大佬们多多见谅......)

ps:

自己项目引入改好的easyexcel包后,在搭建时可能会报一些错误,一般百度可解决,有可能就是差了一些jar包。我这个项目是差了这个jar包:

  1. <dependency>
  2. <groupId>org.apache.commons</groupId>
  3. <artifactId>commons-collections4</artifactId>
  4. <version>4.1</version>
  5. </dependency>

=========================================================================

分享一些可能会遇到的坑:

1.

 这一步容易输入没反应还是啥,请将复制的 "-" 删掉再手动敲一个"-"即可(只用改-jar前面那个-即可)

2.

原文只提供了一个rule的写法,当时我后面参照着写又搞出了一大堆毛病,还是附一个后续rule的写法吧......(应该是对的,注意每次执行的时候改成你保存这个rule的文件名哈)

rule org.apache.poi.**  com.mytest.poi.@1

rule org.apache.poi.ooxml.**  com.mytest.poi-ooxml.@1

rule org.apache.poi.ooxml.schemas.**  com.mytest.poi-ooxml-schemas.@1

3.

自己去github把easyexcel的源码down下来,这一步应该就不用我多做了吧......然后修改pom中对应的原有的依赖,引入本地jar。

注意修改项目那些类的import导入路径,用 ctrl+shift+r 全局替换

大概长这样?太久远我也忘了,反正只要启动不爆红就行......

我自己的项目结构是这样的

 附:本地jar引入的pom文件写法(或者groupId可以改一下?可能会有bug,我才疏学浅):

  1. <dependency>
  2. <groupId>com.alibaba</groupId>
  3. <artifactId>my-poi</artifactId>
  4. <version>3.17</version>
  5. <scope>system</scope>
  6. <systemPath>${project.basedir}/lib/my-poi-3.17.jar
  7. </systemPath>
  8. </dependency>
  9. <dependency>
  10. <groupId>com.alibaba</groupId>
  11. <artifactId>my-poi-ooxml</artifactId>
  12. <version>3.17</version>
  13. <scope>system</scope>
  14. <systemPath>${project.basedir}/lib/my-poi-ooxml-3.17.jar
  15. </systemPath>
  16. </dependency>
  17. <dependency>
  18. <groupId>com.alibaba</groupId>
  19. <artifactId>my-poi-ooxml-schemas</artifactId>
  20. <version>3.17</version>
  21. <scope>system</scope>
  22. <systemPath>${project.basedir}/lib/my-poi-ooxml-schemas-3.17.jar
  23. </systemPath>
  24. </dependency>

此时建议启动一下项目,看有没有报错啥的,当时我又差了一个jar包......反正百度完错误加上去就行了

还是附上一个完整的pom文件吧:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.alibaba</groupId>
  6. <artifactId>easyexcel</artifactId>
  7. <version>2.2.6</version>
  8. <packaging>jar</packaging>
  9. <name>easyexcel</name>
  10. <description>easyexcel is a excel handle tools written in Java</description>
  11. <url>https://github.com/alibaba/easyexcel</url>
  12. <inceptionYear>2018</inceptionYear>
  13. <properties>
  14. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  15. <jdk.version>1.6</jdk.version>
  16. <gpg.skip>true</gpg.skip>
  17. <maven.javadoc.skip>true</maven.javadoc.skip>
  18. </properties>
  19. <scm>
  20. <url>https://github.com/alibaba/easyexcel</url>
  21. <connection>scm:git:https://git@github.com/alibaba/easyexcel.git</connection>
  22. </scm>
  23. <!--<repositories>-->
  24. <!--<repository>-->
  25. <!--<id>local-file</id>-->
  26. <!--<url>file://${basedir}/lib/</url>-->
  27. <!--<layout>default</layout>-->
  28. <!--</repository>-->
  29. <!--</repositories>-->
  30. <organization>
  31. <name>Alibaba Group</name>
  32. <url>https://github.com/alibaba</url>
  33. </organization>
  34. <developers>
  35. <developer>
  36. <id>jipengfei</id>
  37. <name>jipengfei</name>
  38. <email>1558143046@qq.com</email>
  39. </developer>
  40. </developers>
  41. <licenses>
  42. <license>
  43. <name>Apache 2</name>
  44. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  45. <distribution>repo</distribution>
  46. <comments>A business-friendly OSS license</comments>
  47. </license>
  48. </licenses>
  49. <dependencies>
  50. <dependency>
  51. <groupId>com.alibaba</groupId>
  52. <artifactId>my-poi</artifactId>
  53. <version>3.17</version>
  54. <scope>system</scope>
  55. <systemPath>${project.basedir}/lib/my-poi-3.17.jar
  56. </systemPath>
  57. </dependency>
  58. <dependency>
  59. <groupId>com.alibaba</groupId>
  60. <artifactId>my-poi-ooxml</artifactId>
  61. <version>3.17</version>
  62. <scope>system</scope>
  63. <systemPath>${project.basedir}/lib/my-poi-ooxml-3.17.jar
  64. </systemPath>
  65. </dependency>
  66. <dependency>
  67. <groupId>com.alibaba</groupId>
  68. <artifactId>my-poi-ooxml-schemas</artifactId>
  69. <version>3.17</version>
  70. <scope>system</scope>
  71. <systemPath>${project.basedir}/lib/my-poi-ooxml-schemas-3.17.jar
  72. </systemPath>
  73. </dependency>
  74. <dependency>
  75. <groupId>cglib</groupId>
  76. <artifactId>cglib</artifactId>
  77. <version>3.1</version>
  78. </dependency>
  79. <dependency>
  80. <groupId>org.slf4j</groupId>
  81. <artifactId>slf4j-api</artifactId>
  82. <version>1.7.26</version>
  83. </dependency>
  84. <dependency>
  85. <groupId>org.ehcache</groupId>
  86. <artifactId>ehcache</artifactId>
  87. <version>3.4.0</version>
  88. </dependency>
  89. <dependency>
  90. <groupId>org.apache.xmlbeans</groupId>
  91. <artifactId>xmlbeans</artifactId>
  92. <version>2.3.0</version>
  93. </dependency>
  94. <!--test-->
  95. <dependency>
  96. <groupId>ch.qos.logback</groupId>
  97. <artifactId>logback-classic</artifactId>
  98. <version>1.2.3</version>
  99. <scope>test</scope>
  100. </dependency>
  101. <dependency>
  102. <groupId>com.alibaba</groupId>
  103. <artifactId>fastjson</artifactId>
  104. <version>1.2.71</version>
  105. <scope>test</scope>
  106. </dependency>
  107. <dependency>
  108. <groupId>org.projectlombok</groupId>
  109. <artifactId>lombok</artifactId>
  110. <version>1.18.8</version>
  111. <scope>test</scope>
  112. </dependency>
  113. <dependency>
  114. <groupId>org.springframework.boot</groupId>
  115. <artifactId>spring-boot</artifactId>
  116. <version>1.5.21.RELEASE</version>
  117. <scope>test</scope>
  118. </dependency>
  119. <dependency>
  120. <groupId>org.springframework.boot</groupId>
  121. <artifactId>spring-boot-starter-web</artifactId>
  122. <version>1.5.21.RELEASE</version>
  123. <scope>test</scope>
  124. </dependency>
  125. <dependency>
  126. <groupId>junit</groupId>
  127. <artifactId>junit</artifactId>
  128. <version>4.12</version>
  129. <scope>test</scope>
  130. </dependency>
  131. </dependencies>
  132. <distributionManagement>
  133. <snapshotRepository>
  134. <id>ossrh</id>
  135. <url>https://oss.sonatype.org/content/repositories/snapshots</url>
  136. </snapshotRepository>
  137. <repository>
  138. <id>ossrh</id>
  139. <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
  140. </repository>
  141. </distributionManagement>
  142. <build>
  143. <plugins>
  144. <!-- code style -->
  145. <plugin>
  146. <groupId>org.apache.maven.plugins</groupId>
  147. <artifactId>maven-pmd-plugin</artifactId>
  148. <version>3.8</version>
  149. <configuration>
  150. <printFailingErrors>true</printFailingErrors>
  151. <verbose>true</verbose>
  152. <rulesets>
  153. <ruleset>rulesets/java/ali-comment.xml</ruleset>
  154. <ruleset>rulesets/java/ali-concurrent.xml</ruleset>
  155. <ruleset>rulesets/java/ali-constant.xml</ruleset>
  156. <ruleset>rulesets/java/ali-exception.xml</ruleset>
  157. <ruleset>rulesets/java/ali-flowcontrol.xml</ruleset>
  158. <ruleset>rulesets/java/ali-naming.xml</ruleset>
  159. <ruleset>rulesets/java/ali-oop.xml</ruleset>
  160. <ruleset>rulesets/java/ali-orm.xml</ruleset>
  161. <ruleset>rulesets/java/ali-other.xml</ruleset>
  162. <ruleset>rulesets/java/ali-set.xml</ruleset>
  163. </rulesets>
  164. <excludes>
  165. <exclude>com/alibaba/excel/event/AnalysisEventListener.java</exclude>
  166. <exclude>com/alibaba/excel/metadata/DataFormatter.java</exclude>
  167. <exclude>com/alibaba/excel/util/DateUtils.java</exclude>
  168. <exclude>com/alibaba/excel/metadata/format/DataFormatter.java</exclude>
  169. <exclude>com/alibaba/excel/metadata/format/ExcelGeneralNumberFormat.java</exclude>
  170. </excludes>
  171. </configuration>
  172. <executions>
  173. <execution>
  174. <id>pmd-check-verify</id>
  175. <phase>validate</phase>
  176. <goals>
  177. <goal>check</goal>
  178. </goals>
  179. </execution>
  180. </executions>
  181. <dependencies>
  182. <dependency>
  183. <groupId>com.alibaba.p3c</groupId>
  184. <artifactId>p3c-pmd</artifactId>
  185. <version>1.3.6</version>
  186. </dependency>
  187. </dependencies>
  188. </plugin>
  189. <plugin>
  190. <groupId>org.apache.maven.plugins</groupId>
  191. <artifactId>maven-compiler-plugin</artifactId>
  192. <configuration>
  193. <source>1.6</source>
  194. <target>1.6</target>
  195. </configuration>
  196. </plugin>
  197. <plugin>
  198. <artifactId>maven-source-plugin</artifactId>
  199. <version>2.1</version>
  200. <configuration>
  201. <attach>true</attach>
  202. </configuration>
  203. <executions>
  204. <execution>
  205. <phase>compile</phase>
  206. <goals>
  207. <goal>jar</goal>
  208. </goals>
  209. </execution>
  210. </executions>
  211. </plugin>
  212. <plugin>
  213. <groupId>org.apache.maven.plugins</groupId>
  214. <artifactId>maven-gpg-plugin</artifactId>
  215. <version>1.6</version>
  216. <executions>
  217. <execution>
  218. <phase>verify</phase>
  219. <goals>
  220. <goal>sign</goal>
  221. </goals>
  222. </execution>
  223. </executions>
  224. </plugin>
  225. <plugin>
  226. <groupId>org.apache.maven.plugins</groupId>
  227. <artifactId>maven-javadoc-plugin</artifactId>
  228. <version>3.1.0</version>
  229. <executions>
  230. <execution>
  231. <id>attach-javadocs</id>
  232. <goals>
  233. <goal>jar</goal>
  234. </goals>
  235. </execution>
  236. </executions>
  237. </plugin>
  238. </plugins>
  239. </build>
  240. </project>

最后项目启动不爆红就行,然后打个jar包,把这4个jar包扔进自己的项目就行了~~~

最后在自己写的模块里把需要引入的相关类的路径改成现在导入的包路径即可(就是import时看仔细,别选成老的apache的就行)

=========================================================================

文末:

感谢阅读新人写的第一篇文章,一直都在白 p 大佬们写的资料,之前在搞这个的时候也发现有人在说虽然有大佬提供了相应的工具,但是自己没时间去搞这些,想要现成的文件。最近项目交付了没这么忙了,也一直在写相关写代码心得。这次终于也能浅浅的贡献一下自己的代码了~

我敲代码的时间也不长,很多地方可能有误,表达方式不对。望各位海涵。

=========================================================================

自用版本的easyexcel下载链接:

https://pan.baidu.com/s/1YLxgLbS0tI4vLkAxHOB1yg?pwd=neu9

提取码: neu9 

参考的链接:jar包冲突解决方案——jar包名修改兼容实现_ooxml-schemas_laodagewo的博客-CSDN博客

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/170267
推荐阅读
相关标签
  

闽ICP备14008679号