Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

Commented Unassigned: XSSFWorkbook Cannot access a closed MemoryStream [13664]

$
0
0
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 **

```
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


Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>