EasyExecl导出两个sheet

具体实现代码如下:

public void export(HttpServletResponse response){
    //设置返回excel的格式为xlsx
    response.reset();
    response.setContentType("application/vnd.openmosix-officedocument.spreadsheetml.sheet;charset=utf-8");
    response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("shopee_shop_category", "utf-8") + ".xlsx");
    com.alibaba.excel.ExcelWriter excelWriter = null;
    try (OutputStream os = response.getOutputStream()) {
        excelWriter = EasyExcel.write(response.getOutputStream()).build();
        WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").head(ShopCategoryExportDto.class).build();
        WriteSheet writeSheet2 = EasyExcel.writerSheet("sheet2").head(ShopCategoryItemExportDto.class).build();
        excelWriter.write(exportDtoList, writeSheet);
        excelWriter.write(itemExportDtoList, writeSheet2);
        excelWriter.finish();
    } catch (IOException e) {
        throw new BaseRuntimeException("导出失败" + e.getMessage());
    }
}

   转载规则


《EasyExecl导出两个sheet》 duan 采用 知识共享署名 4.0 国际许可协议 进行许可。
  目录