Java使用easyExcel導(dǎo)出excel數(shù)據(jù)案例
easyExcel簡介:
Java領(lǐng)域解析、生成Excel比較有名的框架有Apache poi、jxl等。但他們都存在一個(gè)嚴(yán)重的問題就是非常的耗內(nèi)存。如果你的系統(tǒng)并發(fā)量不大的話可能還行,但是一旦并發(fā)上來后一定會(huì)OOM或者JVM頻繁的full gc。easyExcel是阿里巴巴開源的一個(gè)excel處理框架,以使用簡單、節(jié)省內(nèi)存著稱。easyExcel采用一行一行的解析模式,并將一行的解析結(jié)果以觀察者的模式通知處理easyExcel能大大減少占用內(nèi)存的主要原因是在解析Excel時(shí)沒有將文件數(shù)據(jù)一次性全部加載到內(nèi)存中,而是從磁盤上一行行讀取數(shù)據(jù),逐個(gè)解析。
1.導(dǎo)入依賴【poi不能低于3.17,不然可能會(huì)報(bào)錯(cuò)】
<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.導(dǎo)出模型
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{ /** * 賬號(hào) */ @ExcelProperty(value = {'賬號(hào)'}, index = 0) private String platformNum; /** * 姓名 */ @ExcelProperty(value = {'姓名'}, index = 1) private String name; /** * 身份證號(hào) */ @ExcelProperty(value = {'身份證號(hào)'}, index = 2) private String idCardNum; /** * 性別 */ @ExcelProperty(value = {'性別'}, index = 3) private String sexName; /** * 年級(jí) */ @ExcelProperty(value = {'年級(jí)'}, index = 4) private String gradeName;/** * 班級(jí) */@ExcelProperty(value = {'班級(jí)'}, index = 5)private String className; /** * 學(xué)費(fèi)繳費(fèi)狀態(tài)名稱 */ @ExcelProperty(value = '學(xué)費(fèi)繳費(fèi)狀態(tài)名稱',index = 6) private String studyFeeStatusName; /** * 書本費(fèi)繳費(fèi)狀態(tài)名稱 */ @ExcelProperty(value = '書本費(fèi)繳費(fèi)狀態(tài)名稱',index = 7) private String bookFeeStatusName; }
4.幾萬條數(shù)據(jù)實(shí)現(xiàn)秒導(dǎo)
到此這篇關(guān)于Java使用easyExcel導(dǎo)出excel數(shù)據(jù)案例的文章就介紹到這了,更多相關(guān)Java easyExcel導(dǎo)出excel內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
