简体   繁体   English

如何使用Apache POI将300万行写入Excel文件

[英]How to write 3 Million rows to an Excel File Using Apache POI

I have more than 2 Million rows for a search criteria in my db which i have to Export into a xlsx file. 我的数据库中有200万以上的搜索条件行,必须将其导出到xlsx文件中。 I am using apache POI SXSSF to achieve that. 我正在使用apache POI SXSSF来实现这一目标。

I am getting the data chunk by chunk from DB with 130+ columns and writing it into WorkSheet by creating multiple sheets, each sheet has 400K rows. 我正在从具有130多个列的DB中逐块获取数据,并通过创建多个工作表将其写入WorkSheet,每个工作表有40万行。 But i am facing the issue when it reaches 1.1M data, my code is not responding after that also it is not throwing any error as well. 但是我遇到的问题是当它达到1.1M数据时,此后我的代码没有响应,也没有引发任何错误。

I have 2 confusions based on this issue. 基于这个问题,我有2个困惑。

  1. Can we handle more than 1 M data on a single WorkBook. 我们可以在单个WorkBook上处理超过1 M的数据吗?
  2. Can Excel handle more than 1M records on multiple sheets. Excel可以处理多张图纸上的超过1M条记录。

It would be disastrous to write 2 million rows in an excel sheet. 在Excel工作表中写入200万行将是灾难性的。 If you have a requirement to write to some file then choose to write in CSV files as it's much lighter than excel. 如果您需要写入某些文件,请选择写入CSV文件,因为它比excel轻得多。
And about the max number of rows allowed--~65k in 2003, 1,048,576 in 2007+ you can also use API SpreadsheetVersion.EXCEL97.getMaxRows() and SpreadsheetVersion.EXCEL2007.getMaxRows() 关于允许的最大行数-2003年约为65k,2007年以上为1,048,576,您还可以使用API​​ SpreadsheetVersion.EXCEL97.getMaxRows()和SpreadsheetVersion.EXCEL2007.getMaxRows()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM