java easyexcel 写入数据到excel中的多个sheet中

本文介绍了如何使用EasyExcel在Spring MVC控制器中实现批量下载上传结果的功能,涉及了HTTP请求处理、参数校验、Excel文件生成及定制单元格写入策略。服务类详细展示了如何通过EasyExcel操作数据并设置列宽,以及CustomCellWriteHandler用于处理Excel样式。

controller方法:

@ApiOperation("下载导入结果")
    @RequestMapping(value = "/downloadUploadResut", method = RequestMethod.POST)
    public void batchDownload(HttpServletRequest request,
                              HttpServletResponse response,
                              @RequestBody  DownloadAssetResultDto  downloadAssetResultDto) throws Exception {

        if(downloadAssetResultDto==null || downloadAssetResultDto.getUploadId()==null){
            throw  new RRException("上传数据ID为空,请先上传数据");
        }

        request.setCharacterEncoding("UTF-8");
        String prefix=".xlsx";
        String fileName="uploadResult";
        String userAgent = request.getHeader("User-Agent");
        String     downLoadPath = URLDecoder.decode(fileName, "UTF-8");
        System.out.println(downLoadPath);
        try {

            response.setContentType("application/vnd.ms-excel");
            fileName = URLEncoder.encode(fileName, "ISO8859-1");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
            response.setHeader("filename",fileName);
            Integer uploadId = downloadAssetResultDto.getUploadId();
            downloadAssetService.downloadUploadResut(response,uploadId);


        } catch (Exception e) {
            e.printStackTrace();
        }

    }

service业务类实现方法:

@Override
    public void downloadUploadResut(HttpServletResponse response,Integer  uploadId) {
        ExcelWriter excelWriter = null;
        try {
            CustomCellWriteHandl
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

成伟平2022

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值