问题
I'm creating an Excel file (xlsx) from C# using OpenXML.
When I create a xlsx file and I open, it has no error.
When I try to attach that file on an e-mail and send it, Excel returns the message "found unreadable content" opening the attached file, with Yes/No button to continue.
Clicking on Yes the file is opened correctly.
This is my code to attach an xlsx file:
byte[] bt = functionToCreateXlsxfile();
MailMessage message = new MailMessage();
System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(
new MemoryStream(bt),
"myfile.xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
attach.ContentDisposition.CreationDate = DateTime.Now;
attach.ContentDisposition.ModificationDate = DateTime.Now;
attach.ContentDisposition.Inline = false;
attach.ContentDisposition.Size = bt.Length;
message.Attachments.Add(attach);
回答1:
Trying having the user save the excel document to their local machine and then open it. If errors still persist, instead of creating a .xlsx file from your code, just create a .xls and see if the same issue occurs.
If both methods above don't help, these two links may help
http://blogs.technet.com/b/emeaoffice/archive/2012/11/29/you-may-receive-quot-unreadable-content-quot-when-opening-files-from-within-excel-2007-if-you-have-a-shellstreams-dll-file.aspx
https://social.technet.microsoft.com/Forums/office/en-US/83907359-df5d-42ff-8f2b-a298e49adc61/error-quotexcel-found-unreadable-content-in-filenamexls-do-you-want-to-recover-the-contents-of?forum=excel
I don't think that this issue is related to your code at all. It seems like this is a common excel error that many people are getting.
Also, give this tool a whirl and see if it may help.
来源:https://stackoverflow.com/questions/27252845/excel-found-unreadable-content-error-opening-a-xlsx-created-from-c-sharp