alibaba / easyexcel

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

3.1.1版本当数据条数接近一万条时,写不进excel,前端下载的excel为0kb,最新版本超过1千条就挂 #4017

Open zy150 opened 2 weeks ago

zy150 commented 2 weeks ago

建议先去看文档

快速开始常见问题

触发场景描述

触发Bug的代码

try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), ArticleInfo.class).build()) {

            WriteSheet writeSheet = EasyExcel.writerSheet().build();
           // 一个页面为100大小目前
            for (int i = 1; i <= allPage ; i++) { // 这里使用allPage参数,即分页查找总页数会导出失败,写死比如10,会成功
                conditions.setCurrentPage(i);
                Response<PagingEsArticleBean> query2 = esArticleService.queryAll(conditions); // 查询数据代码
                PagingEsArticleBean obj = query2.getObj();
                result = obj.getResult(); // 写入的对象列表
                allPage = obj.getTotalPage();
                // 写入
                excelWriter.write(result, writeSheet);
            }
        }catch (Exception e) {
            // 重置response
            response.reset();
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            Map<String, String> map = MapUtils.newHashMap();
            map.put("status", "failure");
            map.put("message", "下载文件失败" + e.getMessage());
            response.getWriter().println(JSON.toJSONString(map));
        }

提示的异常或者没有达到的效果

在3.1.1版本写5000条可以,用最新的4版本,目前测试仅1000条左右可以写入。 我的数据量比较大,一行数据导出来excel为7KB,1000条为1M多吧,查询出来的总数据是1万多条,但是就是写不进去,下载的excel为0KB image 不知道什么问题,导出的过程中,java内存变化并不明显,变化幅度也就100M左右,给jvm加了1个G堆,2个G栈都不行 后端也不报错,实在不知道是哪里的问题了,配置文件限制请求大小为100M,也不是这里的问题 是因为有的数据的字段在一栏中的内容过多导致的吗,因为这些数据是文章数据,有个字段是文章内容 image

psxjoy commented 2 weeks ago

I suggest temporarily isolating the front-end impact. Try saving the generated file directly to your local machine to check if it’s correct. If the backend generates the Excel file properly but the error occurs during the front-end download, you can then continue troubleshooting.

zy150 commented 1 week ago

已经尝试过了,直接存到本地,与前端下载的效果是一样的,数据一多就是0kb,因为不报任何错,很奇怪

XB-mx commented 1 week ago

不要关闭流试试

psxjoy commented 1 week ago

It looks like the problem is in the business logic. I tested exporting 500,000 rows of data, and both local saving and browser transfer worked fine.

看上去是业务代码处理有问题。我尝试导出50万条数据,本地保存和浏览器传输都是正常的。