SXSSFWorkbook生成损坏的文件

发布于 2025-02-09 19:34:02 字数 458 浏览 1 评论 0原文

我正在使用Apache POI 5.2.0来编写大型Excel文件(例如20K记录或更多)。因此,由于服务器上的内存较低,我正在使用SXSSFWorkBook。该过程有效。我可以使用MS Excel打开File Excel,并且效果很好。 这些文件将由浏览器上传到另一个系统上。但是,当系统验证文件时,抛出了错误:“文件已损坏...”。 但是,如果我在一代后打开文件,并且保存文件,则在将其上传到外部系统上时,它可以工作。 我试图做这个事情:生成文件后,我在不做任何事情的情况下使用XSSFWorkbook重新捕获文件(仅在XSSF实例上进行密切操作)。 通过这种方式,生成的文件在外部系统上起作用,而无需生成任何操作。

不幸的是,我无法执行此操作,因为大型XSSF部分会导致作业崩溃(因为它将所有Excel文件记录加载到内存上)。 有什么想法吗?

编辑:打开并保存后,生成的文件的重量比同一文件的重量低。因此,文件中有些变化,但我不知道是什么。我怎么能看到发生了什么变化?

I'm using apache poi 5.2.0 to write large excel file (like 20k records or more). So i'm using SXSSFWorkbook because of low memory on server. The process works. I can open the file excel with ms excel and it works great.
The files will be uploaded on another system by browser. But when the system validates the file an error is thrown: "The file is corrupted...".
However, if I open the file after generation, and I save it, it works when I upload it on the external system.
I tried to do this thing: after generating the file, I re-take the file with a XSSFWorkbook without doing nothing (only the close action on XSSF instance).
In this way the file generated works on external system without any action after generation.

Unfortunately i can't do this, because with large excel the XSSF part causes the crash of job (because it load all excel file record on memory).
Any idea?

Edit: the file generated has a lower weight than the same file after I open and save it. So, something change in the file, but I don't know what. How can I see what is changed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文