I\'m trying to return a openXML spreadsheetdocument as a byte[] which I can then use to allow my MVC to send that file to a user. here is my spreadsheetdocument method to re
I had a similar problem with a Word document. I solved this by using the byte array outsite the using, like:
byte[] returnBytes = null;
using (MemoryStream mem = new MemoryStream())
{
// your code
returnBytes = mem.ToArray();
}
return returnBytes;
I know that this is late, but I believe it is because you are not calling close on your spreadsheet document after you are finished with it. Make sure you close the document before returning the memory stream to commit all underlying streams used by the document.
// code omitted for clarity...
workbookpart.Workbook.Save();
spreadsheetDocument.Close();
return mem.ToArray()
http://msdn.microsoft.com/en-gb/library/documentformat.openxml.packaging.spreadsheetdocument(v=office.14).aspx