We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.cells Excel found unreadable content

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.
memStream = GenerateReport(_reportType);
Response.Clear();
Response.ClearContent();
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 ?

Hi,


Thanks for providing us code segment and details.

Could you try to change the line of code in your code segment:
i.e.,
Response.ContentType = “application/vnd.ms-excel”;
to:
Response.ContentType = “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”;

and uncomment it if it works fine for your issue.

Alternatively, you may simply try to use the following line of code instead:
e.g
Sample code:

//Save in Excel2007/2010/2013 XLSX file format
wbDesigner.Workbook.Save(Response, “Filename.xlsx”, ContentDisposition.Attachment, new OoxmlSaveOptions());
Response.End();

Let us know if you still have any issue.

Thank you.

Thanks for reply.

Error is still there with same message after using code -
Response.ContentType = “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”;

I don’t want to use alternative method.code of Saving to Response because of code architectural decision.

Please help me on this issue.

Hi,


Please create a simple sample project (runnable) using latest Aspose.Cells APIs, zip it and post us here, we will check it soon.

Thank you.

Please have the sample app attached here.

Hi,


Thanks for the sample project with template file.

Please add the following line (in bold) to your code segment, it would work fine as I tested:
e.g
Sample code:

protected void Page_Load(object sender, EventArgs e)
{
string templatePath = GetTemplateFilePath();
Report rpt = new Report(templatePath);
MemoryStream memStream = rpt.GenerateReport(_reportType);

Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = false;

Response.ContentType = GetResponseContentType();

Response.AddHeader(“content-disposition”, “attachment; filename=” + GetOutputFileName());

Response.ContentEncoding = Encoding.UTF8;

// memStream.Position = 0;
memStream.Seek(0, SeekOrigin.Begin);
memStream.Capacity = (int)memStream.Length;
Response.BinaryWrite(memStream.ToArray());

Response.Flush();
Response.End();
memStream.Dispose();
memStream.Close();

HttpContext.Current.ApplicationInstance.CompleteRequest();
}

Let us know if you still have any issue.

Thank you.

Thanks. It works now. :slight_smile: Let me try this change in my application code & will revert here for any further queries.

Hi,


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

Thank you.