async-excel實(shí)現(xiàn)多sheet異步導(dǎo)出方法詳解
業(yè)務(wù)上如果需要單sheet導(dǎo)出,有時(shí)有需要將多個(gè)單sheet導(dǎo)出合并到一個(gè)excel里面此時(shí),代碼寫(xiě)起來(lái)也是頗為蛋碎,但是在async-excel中,你可以不改變?cè)腥魏芜壿?,只需要在增加一個(gè)簡(jiǎn)單的controller方法即可
具體代碼如下:
@RequestMapping("/exports") public Long exports() { DataExportParam<Oplog> param = new DataExportParam<>(); param.setExportFileName("導(dǎo)出測(cè)試"); param.setLimit(2); //多個(gè)sheet導(dǎo)出時(shí),行數(shù)計(jì)算為所有sheet的總行數(shù),順序?yàn)閭魅霐?shù)據(jù)組的順序 Long taskId = excelService .doExport(param, OplogExportHandle.class, OplogExportHandleA.class); return taskId; }
不同參數(shù)如何處理?
DataExportParam 內(nèi)部攜帶了個(gè)map,你可以自由傳參,在不同的handler中可以按需獲取
sheet1
@ExcelHandle public class OplogExportHandle implements ExportHandler<OplogExportModel> { @Autowired IOplogService oplogService; @Override public void init(ExcelContext context, DataParam param) { ExportContext ctx = (ExportContext) context; //此處的sheetNo會(huì)被覆蓋,為了兼容多sheet WriteSheet sheet = EasyExcel.writerSheet(0, "第一個(gè)sheet").head(OplogExportModel.class).build(); ctx.setWriteSheet(sheet); } @Override public void beforePerPage(ExportContext ctx, DataExportParam param) { //每頁(yè)開(kāi)始處理前 } @Override public ExportPage<OplogExportModel> exportData(int startPage, int limit, DataExportParam param) { //你的業(yè)務(wù)邏輯 return result; } }
sheet2
@ExcelHandle public class OplogExportHandleA implements ExportHandler<OplogExportModel> { @Autowired IOplogService oplogService; @Override public void init(ExcelContext context, DataParam param) { ExportContext ctx = (ExportContext) context; //此處的sheetNo會(huì)被覆蓋,為了兼容一個(gè)文件多sheet導(dǎo)出 WriteSheet sheet = EasyExcel.writerSheet(0, "第二個(gè)sheet").head(OplogExportModel.class).build(); ctx.setWriteSheet(sheet); } @Override public ExportPage<OplogExportModel> exportData(int startPage, int limit, DataExportParam param) { //你的業(yè)務(wù)邏輯 return result; } }
效果如下
到此這篇關(guān)于async-excel實(shí)現(xiàn)多sheet異步導(dǎo)出方法詳解的文章就介紹到這了,更多相關(guān)async-excel多sheet異步導(dǎo)出內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java swing 實(shí)現(xiàn)加載自定義的字體
這篇文章主要介紹了java swing 實(shí)現(xiàn)加載自定義的字體,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11Java使用DateFormatter格式化日期時(shí)間的方法示例
這篇文章主要介紹了Java使用DateFormatter格式化日期時(shí)間的方法,結(jié)合具體實(shí)例分析了java使用DateFormatter格式化日期時(shí)間的相關(guān)操作技巧,需要的朋友可以參考下2017-04-04Java線程池運(yùn)行狀態(tài)監(jiān)控實(shí)現(xiàn)解析
這篇文章主要介紹了Java線程池運(yùn)行狀態(tài)監(jiān)控實(shí)現(xiàn)解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10SpringSecurity?表單登錄的實(shí)現(xiàn)
本文主要介紹了SpringSecurity?表單登錄的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12Java中反射動(dòng)態(tài)代理接口的詳解及實(shí)例
這篇文章主要介紹了Java中反射動(dòng)態(tài)代理接口的詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-04-04Mybatis-Plus自動(dòng)生成代碼的實(shí)現(xiàn)示例
在工作中,程序員很多時(shí)候都是在寫(xiě)類(lèi)似的代碼,可以使用自動(dòng)生成代碼,本文主要介紹了Mybatis-Plus自動(dòng)生成代碼的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2023-11-11jdbc連接數(shù)據(jù)庫(kù)實(shí)例詳解
在本篇內(nèi)容里小編給大家分享了關(guān)于jdbc如何連接數(shù)據(jù)庫(kù)的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們學(xué)習(xí)下。2019-02-02Java利用TCP實(shí)現(xiàn)服務(wù)端向客戶端消息群發(fā)的示例代碼
這篇文章主要為大家詳細(xì)介紹了Java如何利用TCP協(xié)議實(shí)現(xiàn)服務(wù)端向客戶端消息群發(fā)功能,文中的示例代碼講解詳細(xì),需要的可以參考下,希望對(duì)你有所幫助2022-08-08