我需要在xlsx文件中写一个超过65000行的结果集.所以我想尝试使用Apache POI 3.7.但我收到OutOfMemoryError的错误:Java堆空间.除了增加似乎无法解决问题的JVM内存之外,我该如何解决这个问题.请帮忙.
简单示例代码:
public static void main(String[] args) throws IOException {
Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
for (int i=0;i<65000;i++){
Row row = sheet.createRow((int) i);
// Create a cell and put a value in it.
Cell cell = row.createCell(0);
cell.setCellValue(1);
// Or do it on one line.
row.createCell(1).setCellValue(1.2);
row.createCell(2).setCellValue(
createHelper.createRichTextString("This is a string"));
row.createCell(3).setCellValue(true);
}
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("test1.xls");
fileOut.flush();
wb.write(fileOut);
fileOut.close();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8556 次 |
| 最近记录: |