Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:27:03+00:00 2026-06-13T02:27:03+00:00

It is my 2nd time dealing with NPOI. I’m creating a workbook from a

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:27:04+00:00Added an answer on June 13, 2026 at 2:27 am

    How about this:

    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();
    

    Modified:

    FileStream xfile = new FileStream(Path.Combine(dldir, filename), FileMode.Create, System.IO.FileAccess.Write);
    hssfwb.Write(xfile);
    xfile.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the 2nd time I have asked this. How do I draw an
I just did a fresh install of SugarCRM this is my 2nd time ever
Currently I have this problem. Client downloads from server successfully only the 1st time.
This is the 2nd time I push my code, and it says Everything up-to-date.
This is only the 2nd time I've tried to use log4net. This is a
For the 2nd <h3>World!</h3> in this sample scenario ( Please note <..> elements are
How can i append 2nd page of a pdf file to the first page.
Here is a problem from Programming Pearls 2nd edition (Chapter 8.7): Considering a real
I am developing an Android application, and when I start my application 2nd time
at the start and end of my program, I have from time import strftime

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.