This project is read-only.

Write to XLSX file issue

Jan 27, 2014 at 11:16 PM
I have an existing excel file (2007) to write to. I open it like in c#
            using (FileStream file = new FileStream(bestand, FileMode.Open, FileAccess.ReadWrite))
                wb1 = new XSSFWorkbook(file);

             // lots of stuff

get the error: must support writing, BaseOutputstream
Jan 30, 2014 at 8:10 PM
Man, you should create another FileStream for write purpose.
Jan 31, 2014 at 11:42 AM
Ok, i have now, but the xlsx file is a mess. Even if I don't add anything to it. Office 2010, libre office and open office can't open.
Feb 16, 2014 at 1:42 AM
Which version are you using? Can you try the 2.0 RC (2.0.6)?
Feb 16, 2014 at 3:41 AM
Hi Tony,

Using version the newest version I suppose.
Mar 6, 2014 at 8:53 AM
Edited Mar 6, 2014 at 9:44 AM
Second that Bug! (Latest version 2.0.6)

At first I thought I did't see right. However, when writing to the same file as before, after modifying file content, the file will be corrupted.

I compared a "good" file with the one created. Removing a couple of hundred bytes with a hex editor at the end of the corrupted file (closing bytes need to be '����PK���� � �ˆ��nZ����', see a good zip file), gave me a perfectly good xlsx file.

I suspect some low level zip creation problem. After opening the file, maybe it does not dispose of all file data correctly. Or, when writing the file it does not delete all existing data in the file on disk? I'll try and look into it a bit more.

Mar 6, 2014 at 9:29 AM
Edited Mar 6, 2014 at 9:45 AM
My workaround:
Open the file stream with file mode "truncate" when writing the modified file to disk. This will make sure the binary stream is written from scratch, i.e. the resulting file is emptied before written to disk!
// open the file, close the file reference
// modify the file (edit cells etc)
// save the modified file: 
FileStream sw = new FileStream("C:\\...\\rep1.xlsx", FileMode.Truncate, FileAccess.Write);
@ tonyqus: an example for opening, modifying, and saving an excel file would be nice to have!
Mar 9, 2014 at 8:19 PM
Would you mind sending the original xlsx file to my mail? I need to figure out the root cause. There are already some fixes in github.
Mar 9, 2014 at 10:37 PM
Hi Tony,

Which mail adres to send to? I could'nt find one by clicking your name.
Mar 9, 2014 at 10:44 PM
Hi Tony,
I hope this is the right mailadres.
Here is the XLSX file which can’t be openend by Open Office and Libre Office and an error in Microsoft office.
Regards Rinaldo
Mar 13, 2014 at 9:08 PM
send the original file and modified file to
Oct 13, 2014 at 7:12 AM
Edited Oct 14, 2014 at 5:35 AM
using new version of npoi i.e(2.1 or 2.06).
It is not able to handle more than 55000 data..
I need to handle more than 100000 data
Some one please help me regarding this.
Oct 15, 2014 at 12:13 PM
Edited Oct 15, 2014 at 12:17 PM
Hi Team ,
I have facing a serious issue with xls or xlsx workbook to insert image through using NPOI library
in Xls we are to not able to add picture in this after calling the add picture method key was not found in this dictionary is shown or
with xlsx But when I try to open the created excel file, I got a message saying Excel found unreadable content in 'output.xlsx'. Do you want to recover the contents of this workbook?