I am using Aspose.Cells to generate Excel file [.xlsx] based on template.
I am following these steps
- Create excel file using aspose cells & save it to memory stream.
e.g.MemoryStream memStream = new MemoryStream(); wbDesigner.Workbook.Save(memStream, SaveFormat.Xlsx); memStream.Seek(0, SeekOrigin.Begin);return memStream;
- returns this stream in calling function & send this stream to HttpResponse
e.g.
Response.ClearContent();memStream = GenerateReport(_reportType);Response.Clear();
Response.ClearHeaders();
try
{
// Response.ContentType = “application/vnd.ms-excel”;
Response.AddHeader(“content-disposition”, “attachment; filename=” + outputFileName);
Response.ContentType = “application/octet-stream”;
// memStream.Position = 0;
memStream.Seek(0, SeekOrigin.Begin);
memStream.Capacity = (int)memStream.Length;
Response.BinaryWrite(memStream.ToArray());
memStream.Close();
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (System.Exception ex)
{
if (!ex.Message.Contains(“The remote host closed the connection”))
throw;
}
With this code excel is generated but when tried to open it, it shows error message as
Excel found unreadable content in ‘filenmae.xlsx’ Do u want to recover contents in workbook?
If i click yes on this message excel file is shown correctly.
Why it is showing error message & how to get rid of it ?