facebooktwittermenuarrow-up

GemBox Support Forum

ExcelFile.SaveXlsx(Stream) is erroring

My company has a license for GemBoxSpreadSheet 35.3.30.1012.

I am making a call as follows:

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("Content-Disposition", "attachment; filename=" + "ExportedChartData.xlsx")
ef.SaveXlsx(Response.OutputStream)

This final line throws the following error:

Cannot open package because FileMode or FileAccess value is not valid for the stream.

When I use ExcelFile.SaveXls(Stream) it works just fine. I don’t wish to buy a new license, so if this is a bug in the version I am using, I would like a solution.

Hi Bryan,

That is a version of GemBox.Spreadsheet 3.5, the bugfix version 1012, which was released in 2011.
I believe the reason why this issue occurs in that old version is because it still used System.IO.Packaging for reading and writing XLSX files and that Microsoft’s packaging API cannot write directly to Response.OutputStream.

So as a solution, you could use a temporary MemoryStream, like the following:

Dim ms As New MemoryStream()
ef.SaveXlsx(ms)
ms.WriteTo(Response.OutputStream)

I hope this helps.

Regards,
Mario