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{ /** * 賬號 */ @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; /** * 學(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)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 華為應(yīng)用分身只能qq和微信嗎2. 小紅書怎么發(fā)原圖尺寸3. qq音樂怎么發(fā)布自己的音樂4. 微博金粉是什么意思 微博鐵粉等級要滿足什么條件5. 網(wǎng)易云音樂同時(shí)播放設(shè)置在哪 與其他應(yīng)用同時(shí)播放設(shè)置教程6. 榮耀30pro怎么微信指紋支付7. qq錢包注銷后qq賬號會(huì)不會(huì)消失8. 快手小游戲怎么取消會(huì)員自動(dòng)續(xù)費(fèi)?快手小游戲取消會(huì)員自動(dòng)續(xù)費(fèi)的方法9. 點(diǎn)淘邀請新人可以賺多少錢 點(diǎn)淘邀請一個(gè)新人多少錢10. 華為手機(jī)怎么取消騰訊視頻自動(dòng)續(xù)費(fèi)