Xlsx format corrupted when downloaded

Hello,


This is the code I am using to download the excel file(generated by aspose).

var workbook = … //Workbook that is created by Aspose
var excelMemoryStream = new MemoryStream();
excelMemoryStream = workbook.SaveToStream();
workbook.Save(excelMemoryStream, SaveFormat.Xlsx);
excelMemoryStream.Seek(0, SeekOrigin.Begin);

HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StreamContent(excelMemoryStream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue(“application/force-download”);
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue(“attachment”);
result.Content.Headers.ContentDisposition.Name = “formName”;
result.Content.Headers.ContentDisposition.FileName = “Report.xlsx”;

I am able to download the excel to my PC but when I open it I get an error(refer attachment).
This does not happen with Xls file format. I need to have the file saved in Xlsx format as it has a higher row limit than Xls file format.

Thanks,
Suraj

Hi,


Please remove the following line of code from your code segment as it is not needed when you are saving to XLSX file format:
e.g
Sample code:
excelMemoryStream = workbook.SaveToStream();

Workbook.SaveToMemoryStream is an older method which would save an XLS file to streams.

Let us know if you still have any issue.

Thank you.

That fixed it. AWSOME!!


Thanks!

Suraj

Hi Suraj,


Thank you for the confirmation on proposed solution. Please feel free to get in touch if you require our further assistance with Aspose APIs.