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

Free Support Forum - aspose.com

Excel found unreadable content in 'doc1.xlsx'.Do you want to recover the contents of this workbook?

Hi,
I 'am using Aspose.Cells in dot.net application to export data to both formats Excel2003(.xls) and Excel2007(.xlsx), my export it goes fine with the format Excel2003,once i change to Excel2007 format i got this message when i try to open the document "Excel found unreadable content in 'doc1.xlsx'.Do you want to recover the contents of this workbook?
if you trust the source of this workbook,click Yes."

once i click yes an other popup comes out saying : "Excel has been able to open the file by removing or repairing the unreadable contents ."

I just get my doc after in right format and data...
I've been looking everywhere , Any ideas on what can be done to avoid this error message??

PS: I've got the product License

Thx

Walid

Hi Walid,

Thanks for considering Aspose.

How do you export data to Excel 2007 .xlsx format, do you use some template file or get data from some data source to fill a new workbook. Could you create a sample test code with the template file (if you use) and post it here to reproduce the issue, we will check your issue soon. Moreover, kindly post your created excel .xlsx file (which displays such error messages).

Thank you.

Hi Amjad,
Thanks for the reply.Well I am using some datasource to fill my workbook, here you 'll find the excel file created and Text File containing the full code of my Export function attached to this mail.

Ps : The same code works fine with Excel2003 Format


Thanks

Walid

Hi Walid,

Thanks for providing us the template files.

We will figure out your issue soon.

And by the way Could you give it a try with the attached version.

Thank you.

Hi,

I still got the same problem with the new version sended by Amjad, here you find the new created file.

Thank You.

Walid

Hi,
After reading the file and saving again, it’s like you accept that Excel repared the file so it don’t show the error message again.
I tried to save the file directly to the disk, and it goes fine no warning comes out (You can find it attached to this mail)!!! but still need the export goes right with the stream.
I attached a web Application test so you can try the export to differents formats and reproduce the error with Excel2007 Format .
Thanks, i will appreciate any help could be given to the current problem

Walid

Hi,
I am gonna send two classes from my project, witch include how i save the file to the stream and output it with Response and how i fill my workbook and save the stream to the Excel2007 format.

if this still not giving help, let me know and i 'll try to make other project showing how it works

i tried to call Response.Flush() after the saving but nothing seems changing, still got the same message.

Thank you

walid

Hi walid,

We have found the problem in your codes. You should use MemoryStream.ToArray() to get the data of the MemoryStream not MemoryStream.GetBuffer().See following codes:

protected void Page_Load(object sender, EventArgs e)
{
Workbook workbook = new Workbook();
MemoryStream ms = new MemoryStream();
workbook.Save(ms, FileFormatType.Excel2007Xlsx);
string contentType = "application/txt";
string fileName = "Book1.xlsx";
SetResponse(Response, fileName, contentType);
Response.BinaryWrite(ms.ToArray());
/ Response.Flush();
Response.End();
}
public void SetResponse(System.Web.HttpResponse response, string fileName, string contentType)
{
response.Clear();
response.AppendHeader("Content-Disposition", string.Format("attachment;filename={0}", fileName));
response.ContentType = contentType;

response.ContentEncoding = System.Text.Encoding.GetEncoding(1252);

}

BTW, you can use Workbook.Save(string fileName, FileFormatType fileFormatType, SaveType saveType, HttpResponse response) method to write file data to repsponse