介绍
Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一些缺陷,比如07版Excel解压缩以及解压后存储都是在内存中完成的,内存消耗依然很大。easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析依然需要100M左右内存,改用easyexcel可以降低到几M,并且再大的excel也不会出现内存溢出;03版依赖POI的sax模式,在上层做了模型转换的封装,让使用者更加简单方便
准备前提linux连接服务开启nacos
第一步导入pom依赖
<properties>
<easyexcel.version>3.0.5</easyexcel.version>
</properties>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>${easyexcel.version}</version>
</dependency>
其他可能需要依赖的pom
<properties>
<mysql.version>5.1.38</mysql.version>
<mybatis-plus.version>3.4.2</mybatis-plus.version>
<druid.version>1.1.9</druid.version>
<easyexcel.version>3.0.5</easyexcel.version>
<fastdss.verson>1.26.4</fastdss.verson>
<fastjson.version>1.2.83</fastjson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>${easyexcel.version}</version>
</dependency>
<dependency>
<groupId>net.oschina.zcx7878</groupId>
<artifactId>

该博客介绍了如何使用EasyExcel来解决Apache POI和jxl在处理Excel时内存消耗大的问题。EasyExcel通过重写POI对07版Excel的解析,显著降低了内存占用,使得处理大型Excel文件不再引发内存溢出。文章详细讲解了引入EasyExcel的依赖、配置应用、编写实体类、Controller、Service、Mapper及监听器的步骤,并提供了批量插入数据的示例代码。
最低0.47元/天 解锁文章
750

被折叠的 条评论
为什么被折叠?



