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實(shí)現(xiàn)貪吃蛇大作戰(zhàn)小游戲(附源碼)
今天給大家?guī)?lái)的是小項(xiàng)目是 基于Java+Swing+IO流實(shí)現(xiàn) 的貪吃蛇大作戰(zhàn)小游戲。實(shí)現(xiàn)了界面可視化、基本的吃食物功能、死亡功能、移動(dòng)功能、積分功能,并額外實(shí)現(xiàn)了主動(dòng)加速和鼓勵(lì)機(jī)制,需要的可以參考一下2022-07-07
Spring Cloud Gateway 記錄請(qǐng)求應(yīng)答數(shù)據(jù)日志操作
這篇文章主要介紹了Spring Cloud Gateway 記錄請(qǐng)求應(yīng)答數(shù)據(jù)日志操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-12-12
SpringBoot解決數(shù)據(jù)庫(kù)時(shí)間和返回時(shí)間格式不一致的問(wèn)題
這篇文章主要介紹了SpringBoot解決數(shù)據(jù)庫(kù)時(shí)間和返回時(shí)間格式不一致的問(wèn)題,文章通過(guò)代碼示例和圖文結(jié)合的方式講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)和工作有一定的幫助,需要的朋友可以參考下2024-03-03
解決IDEA springboot"spring-boot-maven-plugin"報(bào)紅問(wèn)題
這篇文章主要介紹了解決IDEA springboot"spring-boot-maven-plugin"報(bào)紅問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
JAVA抽象類和抽象方法(abstract)實(shí)例分析
這篇文章主要介紹了JAVA抽象類和抽象方法(abstract),結(jié)合實(shí)例形式分析了java抽象類及抽象方法相關(guān)定義、使用技巧與操作注意事項(xiàng),需要的朋友可以參考下2019-11-11
springcloud Zuul動(dòng)態(tài)路由的實(shí)現(xiàn)
這篇文章主要介紹了springcloud Zuul動(dòng)態(tài)路由的實(shí)現(xiàn),詳細(xì)的介紹了什么是Zuu及其動(dòng)態(tài)路由的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11

