Excel“找到不可读的内容";打开从C#创建的xlsx时出错 [英] Excel "found unreadable content" error opening a xlsx created from C#

查看:103
本文介绍了Excel“找到不可读的内容";打开从C#创建的xlsx时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm creating an Excel file (xlsx) from C# using OpenXML.

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

When I create a xlsx file and I open, it has no error.

当我尝试将该文件附加到电子邮件上并发送时,Excel会返回消息找到不可读的内容",打开附件,并使用是/否"按钮继续.

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.

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

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

推荐答案

尝试让用户将excel文档保存到本地计算机,然后将其打开.如果错误仍然存​​在,则可以通过创建.xls并查看是否发生相同的问题,而不是从代码中创建.xlsx文件.

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

我认为这个问题根本与您的代码无关.看来这是许多人都遇到的常见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.

这篇关于Excel“找到不可读的内容";打开从C#创建的xlsx时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆