您的位置:首页技术文章
文章详情页

Java使用easyExcel导出excel数据案例

【字号: 日期:2022-05-25 17:49:28浏览:93作者:猪猪

easyExcel简介:

Java领域解析、生成Excel比较有名的框架有Apache poi、jxl等。但他们都存在一个严重的问题就是非常的耗内存。如果你的系统并发量不大的话可能还行,但是一旦并发上来后一定会OOM或者JVM频繁的full gc。easyExcel是阿里巴巴开源的一个excel处理框架,以使用简单、节省内存著称。easyExcel采用一行一行的解析模式,并将一行的解析结果以观察者的模式通知处理easyExcel能大大减少占用内存的主要原因是在解析Excel时没有将文件数据一次性全部加载到内存中,而是从磁盘上一行行读取数据,逐个解析。

1.导入依赖【poi不能低于3.17,不然可能会报错】

<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.17</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.17</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>1.1.2-beta5</version></dependency>

2.控制层

<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.17</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.17</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>1.1.2-beta5</version></dependency>

3.导出模型

package com.iflytek.edu.hnezxjgl.model;import com.alibaba.excel.annotation.ExcelProperty;import com.alibaba.excel.metadata.BaseRowModel;import lombok.Data;@Datapublic class ExportModel extends BaseRowModel{ /** * 账号 */ @ExcelProperty(value = {'账号'}, index = 0) private String platformNum; /** * 姓名 */ @ExcelProperty(value = {'姓名'}, index = 1) private String name; /** * 身份证号 */ @ExcelProperty(value = {'身份证号'}, index = 2) private String idCardNum; /** * 性别 */ @ExcelProperty(value = {'性别'}, index = 3) private String sexName; /** * 年级 */ @ExcelProperty(value = {'年级'}, index = 4) private String gradeName;/** * 班级 */@ExcelProperty(value = {'班级'}, index = 5)private String className; /** * 学费缴费状态名称 */ @ExcelProperty(value = '学费缴费状态名称',index = 6) private String studyFeeStatusName; /** * 书本费缴费状态名称 */ @ExcelProperty(value = '书本费缴费状态名称',index = 7) private String bookFeeStatusName; }

4.几万条数据实现秒导

Java使用easyExcel导出excel数据案例

到此这篇关于Java使用easyExcel导出excel数据案例的文章就介绍到这了,更多相关Java easyExcel导出excel内容请搜索好吧啦网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好吧啦网!

标签: excel
相关文章: