2016-07-14 43 views
1

是否可以保存工作簿并将其保存,而无需将编辑的文件复制到基本文件上?以不同名称保存编辑/写入工作簿

这里是我的代码:

File file = new File("base.xlsx"); 
Workbook workbook = WorkbookFactory.create(file); 

Sheet sheet = workbook.getSheet("data"); 
... 
//creating rows and cells, writing stuff 
... 

//saving 
FileOutputStream fos = new FileOutputStream("edited.xlsx"); 
workbook.write(fos); 
workbook.close(); 
fos.close(); 
//now both the base.xlsx and edited.xlsx contain all the new and previous data - and are exactly the same size 

//using only 
workbook.close(); 
//the workbook file size changes (approximately to the same as edited.xlsx) and the timestamp is current 
//BUT the data doesn't get saved 

唯一的可能,我知道的是用一个InputStream(但后来我得到了内存(10MB .xlsx文件和2GB的堆空间))

令人困惑的部分是:为什么base.xlsx文件被编辑,如果我把它写出到另一个文件?

回答

2

随着2016年7月(Apache的POI 3.15 beta 2版本),这还不支持

在POI,我们称这种就地写。截至最近,底层文件格式模块(POIFS和OPC)现在都支持这一功能。 (他们没有很长一段时间,这就是为什么POI已经成长起来了,就像它为了保存一样)。但是,没有任何格式特定的模块已更新以利用此功能。因此,所有打开的文件在的usermodel水平(例如WorkbookXLSFSlideShowHWPFDocument)目前只支持写出到一个新的流

如果您对此感兴趣,虫子看是#57919#59287

如果这些事情给你,你想把一些编码时间在帮忙,看看contribution guide然后加入the dev list和人们可以给你指针!

+0

谢谢你的解释! – Beig

相关问题