I am using the following code to create an excel file using NPOI library. I am getting "Cannot access a closed stream" error. I have gone through a few threads and tried to implement the suggestions, but its not working.
XSSFWorkbook wb = null;
using (FileStream file = new FileStream("D:\\Test_Output.xlsx",
FileMode.Open, FileAccess.Read))
{
wb = new XSSFWorkbook(file);
}
MemoryStream mstream = new MemoryStream();
wb.Write(mstream);
FileStream xfile = new FileStream(Path.Combine(taskpath, "Test_Output.xlsx"),
FileMode.OpenOrCreate, 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();
Kindly help me out in this regard.
Thanks