alibaba / easyexcel

快速、简洁、解决大文件内存溢出的java处理Excel工具
https://easyexcel.opensource.alibaba.com
Apache License 2.0
31.65k stars 7.46k forks source link

处理20万数据进行数据导出分为32个sheet到一个文件里,本地代码跑起来好好的 一放生产环境就报Can not close IO #3391

Closed AeRocky closed 6 days ago

AeRocky commented 12 months ago

public static void exportSheet(HttpServletResponse response, String fileName, List sheetName, List<List> list, Class clazz) { response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding(Charsets.UTF_8.name()); ServletOutputStream outputStream = null; ExcelWriter excelWriter = null; try { fileName = URLEncoder.encode(fileName, Charsets.UTF_8.name()); response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); outputStream = response.getOutputStream(); excelWriter = EasyExcel.write(outputStream, clazz).build();

        int i = 0;
        int k = 0;
        for (List<T> c : list) {
            WriteSheet writeSheet = EasyExcel.writerSheet(i++, sheetName.get(k++)).head(clazz).build();
            excelWriter.write(c, writeSheet);
        }
        excelWriter.finish();
        outputStream.flush();
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

``

Sean-214 commented 12 months ago

excelWriter.finish(); 调这个方法时输出流应该已经关闭了。

AeRocky commented 12 months ago

大佬那应该怎么解决呢 @Sean-214

gongxuanzhang commented 2 weeks ago

你好,我们发现此Issue已经超过三个月没有活动了,为了更好的帮助您解决问题,我们将在两周后关闭此Issue,如果您仍然有问题,请在两周内内回复此Issue,谢谢!如果您已经解决或者不需要帮助,请忽略此消息。