Recently, I had downloaded NOPI 2.1.X and tried to export Excel 2007 file(.xlsx), but I always got exception from the code, it can not to write to MemeoryStream, and the Exception to be " System.ObjectDisposedException".
////////////////////////////////////////////
using NPOI.SS.UserModel;
using NPOI.XSSF;
using NPOI.XSSF.UserModel;
IWorkbook workbook = new XSSFWorkbook();
XSSFSheet worksheet = (XSSFSheet)workbook.CreateSheet("Sheet A_20");
....
....
MemoryStream MS = new MemoryStream();
workbook.Write(MS); // ((System.IO.Stream)(MS)).Length' threw an exception of type 'System.ObjectDisposedException'", Cannot access a closed Stream.
workbook = null;
MS.Close();
MS.Dispose();
Does anyone has ideas?
Comments: ** Comment from web user: Schmellow **
////////////////////////////////////////////
using NPOI.SS.UserModel;
using NPOI.XSSF;
using NPOI.XSSF.UserModel;
IWorkbook workbook = new XSSFWorkbook();
XSSFSheet worksheet = (XSSFSheet)workbook.CreateSheet("Sheet A_20");
....
....
MemoryStream MS = new MemoryStream();
workbook.Write(MS); // ((System.IO.Stream)(MS)).Length' threw an exception of type 'System.ObjectDisposedException'", Cannot access a closed Stream.
workbook = null;
MS.Close();
MS.Dispose();
Does anyone has ideas?
Comments: ** Comment from web user: Schmellow **
```
workbook.Write(MS);
```
Is that exatly the part that throws exception, or are you trying to query your memory stream right after?
Writing to stream alone seems to be working for me both in 2.1.3.1 and 2.2.0, however stream is explicitely closed in the implementation of this method