Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using EPPlus with a MemoryStream

Tags:

c#

excel

epplus

I am using EPPlus to generate an XLSX file in C#. As soon as I instantiate the ExcelPackage with a memory stream - I get the error:

"A disk error occurred during a write operation. (Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT))"

Code is:

MemoryStream stream = new MemoryStream();  using (ExcelPackage package = new ExcelPackage(stream)) {     ... } 

Has anyone else seen this?

like image 798
dan Avatar asked Apr 21 '11 00:04

dan


1 Answers

None of the other answers quite got me there (the Excel worksheet was always empty), but this worked for me:

using (var package = new ExcelPackage()) {     var worksheet = package.Workbook.Worksheets.Add("Worksheet Name");      worksheet.Cells["A1"].LoadFromCollection(data);      var stream = new MemoryStream(package.GetAsByteArray()); } 
like image 176
Noah Heldman Avatar answered Sep 17 '22 12:09

Noah Heldman