将XSSF文件逐行写入输出流? (Java 中的 POI)
我有大量数据,我想逐行流式传输。我认为在更改每行的值后调用 workbook.write(stream) 会将每个写入附加到输出流上,但我错了。事实上,文件大小表明/匹配我拥有的行数,但文件本身内只有 1 行(这是写入的第一行)。
有办法做到这一点吗?就像我可以使用文本文件一样吗?
我查看了 BigGrid 的实现,它对于我想要做的事情来说看起来有点过分了。
谢谢!
I have a huge amount of data which I would like to stream row by row. I thought calling workbook.write(stream) after changing the value of each row would append each write onto the output stream, but I was wrong. As it is, the file size suggests/matches the amount of rows I have, but there is only 1 row inside the file itself (which is the first row written).
Is there a way to accomplish this? Much like I would be able to using a text file?
I've taken a look at the BigGrid implementation, and it looks a bit overkill for what I'm trying to do.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法一次性对整个文件进行流式写入,文件格式不是这样工作的。文件的不同部分之间存在引用,从而排除了这种情况。文件格式与 CSV 不同!
相反,您可以做的是将一些小部分保存在内存中,将电子表格的大部分进行流式写入临时文件,然后以低内存方式重新组装以进行输出。为此,请查看(相当新的)SXSSF 用户模型代码兴趣点。
You can't do a streaming write of the whole file in one go, the file format doesn't work like that. There are references between different parts of the file that preclude it. The file format just isn't like a CSV!
Instead, what you can do is hold a few small parts in memory, do a streaming write of the large parts of the spreadsheet to a temporary file, then re-assemble it in a low memory manner for output. To do that, look at the (fairly new) SXSSF usermodel code in POI.