Memory Stream making corrupted file


Sorry if this is a duplicate, I looked around the forums but nothing seemed to be of help.

I’m trying to return an excel stream from web api. And the resulting excel file opens with “We found a problem with some content in ‘export.xlsx’. Do you want us to try to recover…”. And clicking yes to that gives a “File is corrupted and cannot be opened”.

MemoryStream mstream = new MemoryStream();, SaveFormat.Xlsx);
mstream.Seek(0, SeekOrigin.Begin);

HttpResponseMessage res = new HttpResponseMessage(System.Net.HttpStatusCode.Ok);
res.Content = new ByteArrayContent(mstream.ToArray());
res.Content.Headers.ContentLength = mstream.Length;
res.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
    FileName = "export.xlsx"
res.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/vnd.openxmlformats");

return res;

And if it matters, this is how I’m handling it in JS:

api.getExport(...).then(res => {
    const blob = new Blob([], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8" });

Does anything look off to you guys? Any help would be greatly appreciated.



Thank you for your query.

We are looking into this issue and need more information. Could you please inform how this file is created i.e. either is it created by Aspose.Cells or some other tool is used to create it? If it is created by using Aspose.Cells, please share the simple console application also which can be used to create this file here. We need this file (export.xlsx) as well which is used in this program for reproducing the issue.


Apologies, I’ve figured it out since then. I had to change the response type on the UI side, to “arraybuffer”.


Good to know that your issue is sorted out. Feel free to contact us at any time if you need further help or have some other issue or queries, we will be happy to assist you soon.