This project is read-only.

saving workbook created from template file

Oct 18, 2012 at 1:23 PM

It is my 2nd time dealing with NPOI. I'm creating a workbook from a template excel file like this.

        string dldir = AppDomain.CurrentDomain.BaseDirectory + "Download\\excel\\";
string uldir = AppDomain.CurrentDomain.BaseDirectory + "Upload\\default_export_file\\";
string filename = DateTime.Now.ToString("yyyy-M-d") + "_" + user.first_name + "_" + query.default_export_filename;

System.IO.File.Delete(Path.Combine(dldir, filename));

//System.IO.File.Copy(Path.Combine(uldir, query.default_export_filename), Path.Combine(dldir, filename));

HSSFWorkbook hssfwb;
(FileStream file = new FileStream(Path.Combine(uldir, query.default_export_filename), FileMode.Open, FileAccess.ReadWrite))
= new HSSFWorkbook(file);

MemoryStream mstream = new MemoryStream();

FileStream xfile = new FileStream(Path.Combine(dldir, filename), FileMode.Create, System.IO.FileAccess.Write);
byte[] bytes = new byte[mstream.Length];
.Read(bytes, 0, (int)mstream.Length);
.Write(bytes, 0, bytes.Length);

But when I checked the created file. It contains nothing. The size is correct. But the contents is just blanks. And I couldn't open it in MS Excel either. I repeated and traced the code but I can't seem to find what is causing it to just write blanks.

Anyone knows why is this happening

FYI: I'm using VS 2010, ASP.Net MVC 4 and NPOI 1.2.5 installed from the NuGet Gallery

Oct 20, 2012 at 11:50 PM

Would you please let me know what content is in the excel? cell values? graphs? or something else? If possible, please share the xls with me. Thanks

Oct 30, 2012 at 10:41 AM



It is already solved here, thank you anyway

May 22, 2014 at 7:09 AM
Dear Sir,
Not working in VS 2010 ( i have already using NPOI 1.2.3 Version for export excel
May 22, 2014 at 10:17 AM
1.2.3 is too old. Please try 1.2.5 or 2.0.6