Java使用easyExcel導出excel數據案例
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內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章: