svn2github / npoi

This is a clone of an SVN repository at http://npoi.googlecode.com/svn/trunk/. It had been cloned by http://svn2github.com/ , but the service was since closed. Please read a closing note on my blog post: http://piotr.gabryjeluk.pl/blog:closing-svn2github . If you want to continue synchronizing this repo, look at https://github.com/gabrys/svn2github
Other
60 stars 50 forks source link

IWorkbook.Write(stream) #19

Closed ssquirrel closed 4 years ago

ssquirrel commented 6 years ago

hello, I am currently using NPOI in my project and I encounter this very weird situation when try to write IWorkbook to file. The write function seems buggy to me. When you do:

var workbook =  WorkbookFactory.Create("template.xlsx"); //open an existing excel file
 //do editing with the workbook
workbook.write(new FileStream("test.xlsx", FileMode.Create))
workbook.close()

Both original file and the new file will be updated. However if you comment out the write() call, nothing would happen. So my question is how am I supposed to update an existing file or save changes to another file only(keeping original file intact)?

many thanks in advance!

ssquirrel commented 6 years ago

It appears that if the underlying type is HSSFWorkbook then there is no problem as the constructor of HSSFWorkbook would close the file stream after construction allowing you to open the stream again to overwrite its content. But that is not the case with XSSFWorkbook. XSSFWorkbook keeps the file stream open until Close(). Subsequent access can only be made read only. Hence it exhibited problem i described above. Either you get a duplicate or nothing.

ssquirrel commented 6 years ago

OK. just worked out a solution. if you open .xlsx file by using WorkbookFactory.Create(stream), the stream would be properly closed so you may open it again to overwrite it.

tonyqus commented 5 years ago

hello, this repo is for synchonization from svn to github only. Please go to https://github.com/tonyqus/npoi/issues to create your issue.