欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

async-excel實現(xiàn)多sheet異步導出方法詳解

 更新時間:2022年12月23日 12:26:48   作者:起風哥  
這篇文章主要介紹了async-excel實現(xiàn)多sheet異步導出方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧

async-excel組件開源地址

業(yè)務上如果需要單sheet導出,有時有需要將多個單sheet導出合并到一個excel里面此時,代碼寫起來也是頗為蛋碎,但是在async-excel中,你可以不改變原有任何邏輯,只需要在增加一個簡單的controller方法即可

具體代碼如下:

    @RequestMapping("/exports")
    public Long exports() {
        DataExportParam<Oplog> param = new DataExportParam<>();
        param.setExportFileName("導出測試");
        param.setLimit(2);
        //多個sheet導出時,行數(shù)計算為所有sheet的總行數(shù),順序為傳入數(shù)據(jù)組的順序
        Long taskId = excelService
            .doExport(param, OplogExportHandle.class, OplogExportHandleA.class);
        return taskId;
    }

不同參數(shù)如何處理?

DataExportParam 內(nèi)部攜帶了個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會被覆蓋,為了兼容多sheet
        WriteSheet sheet = EasyExcel.writerSheet(0, "第一個sheet").head(OplogExportModel.class).build();
        ctx.setWriteSheet(sheet);
    }
    @Override
    public void beforePerPage(ExportContext ctx, DataExportParam param) {
        //每頁開始處理前
    }
    @Override
    public ExportPage<OplogExportModel> exportData(int startPage, int limit, DataExportParam param) {
        //你的業(yè)務邏輯
        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會被覆蓋,為了兼容一個文件多sheet導出
        WriteSheet sheet = EasyExcel.writerSheet(0, "第二個sheet").head(OplogExportModel.class).build();
        ctx.setWriteSheet(sheet);
    }
    @Override
    public ExportPage<OplogExportModel> exportData(int startPage, int limit, DataExportParam param) {
        //你的業(yè)務邏輯
        return result;
    }
}

效果如下

到此這篇關(guān)于async-excel實現(xiàn)多sheet異步導出方法詳解的文章就介紹到這了,更多相關(guān)async-excel多sheet異步導出內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論