Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zy150 opened this issue Oct 10, 2024 · 4 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@zy150
Copy link

zy150 commented Oct 10, 2024

建议先去看文档

快速开始常见问题

触发场景描述

触发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

@zy150 zy150 added the bug Something isn't working label Oct 10, 2024
@psxjoy
Copy link
Collaborator

psxjoy commented Oct 10, 2024

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.

@psxjoy psxjoy added help wanted Extra attention is needed and removed bug Something isn't working labels Oct 10, 2024
@zy150
Copy link
Author

zy150 commented Oct 16, 2024

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

@XB-mx
Copy link

XB-mx commented Oct 16, 2024

不要关闭流试试

@psxjoy
Copy link
Collaborator

psxjoy commented Oct 16, 2024

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万条数据,本地保存和浏览器传输都是正常的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants