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

标签 c# excel openxml

我正在使用 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旋转工具看看是否有帮助。

关于c# - 打开从 C# 创建的 xlsx 时出现 Excel "found unreadable content"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27252845/

相关文章:

vba - 在 VBA 中声明字典

c# - .NET 中的模块化系统能够在运行时更改

c# - 从泛型方法返回对象作为接口(interface)

excel - 输入框运行时滚动

asp.net - 如何将多个页面的gridview数据导出到excel文档中?

c# - ClosedXml 无法访问已关闭的流

c# - 从模板创建 PowerPoint 2007 演示文稿

c# - 如何使用 Open XML 和 SAX 以编程方式检测空行?

c# - 如何将图像放置在其中心而不是左上角?

c# - 如何以编程方式在 Web 窗体的 TextBox 中设置 BackColor?