Joh*_*n B 9 java apache-poi sxssf
根据SXSSF(Streaming Usermodel API)文档:
SXSSF(package :)
org.apache.poi.xssf.streaming是XSSF 的API兼容流式扩展,用于在必须生成非常大的电子表格时使用,并且堆空间有限.SXSSF通过限制对滑动窗口内行的访问来实现其低内存占用,而XSSF允许访问文档中的所有行.不再在窗口中的旧行变得不可访问,因为它们被写入磁盘.
但是,在提供的示例中,刷新发生在工作簿被赋予写入文件的文件位置之前.
public static void main(String[] args) throws Throwable {
Workbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
Sheet sh = wb.createSheet();
for(int rownum = 0; rownum < 1000; rownum++){
Row row = sh.createRow(rownum);
for(int cellnum = 0; cellnum < 10; cellnum++){
Cell cell = row.createCell(cellnum);
String address = new CellReference(cell).formatAsString();
cell.setCellValue(address);
}
}
// Rows with rownum < 900 are flushed and not accessible
for(int rownum = 0; rownum < 900; rownum++){
Assert.assertNull(sh.getRow(rownum));
}
// ther last 100 rows are still in memory
for(int rownum = 900; rownum < 1000; rownum++){
Assert.assertNotNull(sh.getRow(rownum));
}
FileOutputStream out = new FileOutputStream("/temp/sxssf.xlsx");
wb.write(out);
out.close();
}
Run Code Online (Sandbox Code Playgroud)
所以这引出了一些问题:
Gag*_*arr 10
类,它的缓冲是SheetDataWriter在org.apache.poi.xssf.streaming.SXSSFSheet
你可能感兴趣的神奇线是:
_fd = File.createTempFile("poi-sxxsf-sheet", ".xml");
Run Code Online (Sandbox Code Playgroud)
就安全而言,可能,但不是肯定......可能值得在poi bugzilla中打开一个错误,并要求将其切换为使用org.apache.poi.util.TempFile允许更多控制的错误.但一般情况下,只要你指定一个有效的属性java.io.tmpdir(或默认对你来说是明智的)你应该没问题
| 归档时间: |
|
| 查看次数: |
10329 次 |
| 最近记录: |