easyexcel与vue配合下载excel_vue+easyexcel下载文件

本文介绍了后端如何使用EasyExcel库将数据写入响应流以生成Excel文件,同时提到前端学习中遇到的挑战和一份包含面试题解析的学习资源分享。
摘要由CSDN通过智能技术生成

后端

设置响应

// 设置响应头
response.setContentType("application/octet-stream;charset=UTF-8");
String returnName = null;
try {
    returnName = URLEncoder.encode(fileName, "UTF-8");
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
}
response.setHeader("Content-Disposition", "attachment;filename=" + returnName);

往response 写入数据

  • 使用easyexcel自带的方法就行
// 这里 指定文件
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();) {
// try (ExcelWriter excelWriter = EasyExcel.write(fileName).build()) {
    if (hasXL) {
        WriteSheet writeSheet2 = EasyExcel.writerSheet(2, "小料费用差异对比").head(DepreciationEquipXLDto.class).build();
        // 获取小料费用差异
        List<DepreciationEquipXLDto> data2 = assetDepreciationSingleDetailService.getDepreciationEquXLCompare(entityList);
        excelWriter.write(data2, writeSheet2);
    }

    if (hasJL) {
        WriteSheet writeSheet = EasyExcel.writerSheet(0, "其他费用差异对比").head(DepreciationOtherDto.class).build();
        // 获取其他费用差异
        List<DepreciationOtherDto> data = assetDepreciationSingleDetailService.getDepreciationOtherCompare(entityList);
        excelWriter.write(data, writeSheet);

        WriteSheet writeSheet1 = EasyExcel.writerSheet(1, "胶料费用差异对比").head(DepreciationEquipJLDto.class).build();
        // 获取胶料费用差异
        List<DepreciationEquipJLDto> data1 = assetDepreciationSingleDetailService.getDepreciationEquJLCompare(entityList);
        excelWriter.write(data1, writeSheet1);
    }

    WriteSheet writeSheet3 = EasyExcel.writerSheet(3, "总费用差异对比").head(DepreciationTotalDto.class).build();
    // 获取总费用差异
    List<DepreciationTotalDto> data3 = assetDepreciationSingleDetailService.getDepreciationTotalCompare(entityList);
    excelWriter.write(data3, writeSheet3);

    // 获取具体的折旧明细
    WriteSheet writeSheet4 = EasyExcel.writerSheet(4, "折旧明细").head(DepreciationSingleDetailDto.class).build();
    // 获取具体的折旧明细
    List<DepreciationSingleDetailDto> data4 = assetDepreciationSingleDetailService.getDepreciationSingleDetail(entityList);
    excelWriter.write(data4, writeSheet4);

} catch (IOException e) {
    throw new RuntimeException(e);
}

前端

最后

一个好的心态和一个坚持的心很重要,很多冲着高薪的人想学习前端,但是能学到最后的没有几个,遇到困难就放弃了,这种人到处都是,就是因为有的东西难,所以他的回报才很大,我们评判一个前端开发者是什么水平,就是他解决问题的能力有多强。

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

分享一些前端面试题以及学习路线给大家

dn.net/topics/618166371)**

分享一些前端面试题以及学习路线给大家

[外链图片转存中…(img-MtWOPXYq-1714142084224)]

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值