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;
        using
(FileStream file = new FileStream(Path.Combine(uldir, query.default_export_filename), FileMode.Open, FileAccess.ReadWrite))
       
{
            hssfwb
= new HSSFWorkbook(file);
       
}

       
MemoryStream mstream = new MemoryStream();
        hssfwb
.Write(mstream);

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

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

Coordinator
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

Hi, 

 

It is already solved here, thank you anyway

May 22, 2014 at 7:09 AM
Dear Sir,
http://office.microsoft.com/en-us/templates/event-budget-TC010336274.aspx?pid=CT101172321033
Not working in VS 2010 (asp.net) i have already using NPOI 1.2.3 Version for export excel
Coordinator
May 22, 2014 at 10:17 AM
1.2.3 is too old. Please try 1.2.5 or 2.0.6