Skip to main content
 首页 » 编程设计

c#之打开从 C# 创建的 xlsx 时出现 Excel "found unreadable content"错误

2024年08月12日31zfyouxi

我正在使用 OpenXML 从 C# 创建一个 Excel 文件 (xlsx)。

当我创建一个 xlsx 文件并打开时,它没有错误。

当我尝试将该文件附加到电子邮件中并发送时,Excel 返回消息“发现无法读取的内容”打开附件,点击是/否按钮继续。

单击是,文件已正确打开。

这是我附加 xlsx 文件的代码:

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); 

请您参考如下方法:

尝试让用户将 excel 文档保存到他们的本地计算机,然后打开它。如果错误仍然存​​在,请不要从您的代码创建 .xlsx 文件,只需创建一个 .xls 并查看是否会出现相同的问题。

如果上述两种方法都不起作用,这两个链接可能会有所帮助

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

我认为这个问题与您的代码完全无关。这似乎是许多人遇到的常见 excel 错误。

另外,给出 this旋转工具看看是否有帮助。