[alibaba/easyexcel]导出excel不添加密码可以正常导出,加了密码后输入密码提示文件损坏

2024-05-16 50 views
3

异常代码

        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("导出excel", "UTF-8") + ".xls");
        @Cleanup("finish") ExcelWriter excelWriter = EasyExcel.write(new BufferedOutputStream(response.getOutputStream()), RiskPersonExcelOutDTO.class)
                .autoCloseStream(Boolean.TRUE).excelType(ExcelTypeEnum.XLSX).needHead(Boolean.TRUE)
                .password("a123456").build();
        //初始化sheet
        WriteSheet writeSheet = EasyExcel.writerSheet().build();
        writeSheet.setSheetNo(1);
        writeSheet.setSheetName("默认表");
        excelWriter.write(list,writeSheet);

异常提示

系统并未出现异常,且加密后的文件一直都是4.0KB

回答

5

尝试直接调出到 文件试试

0

这个问题是否已经解决?未解决请重新打开

2

怎么处理的2.X也遇到此问题