为什么出现错误消息,同时打开.xls文件 [英] Why showing error message while opening .xls file

查看:223
本文介绍了为什么出现错误消息,同时打开.xls文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net,C#应用程序,我们正在生成和下载.xls文件。但是,当我试图打开,它给的消息

In my asp.net, C# application we are generating and downloading .xls file. But when I'm trying to open, it's giving a message

你试图打开,'filename.xls'文件,是在不同的
  比由文件扩展名指定的格式。验证文件
  未破坏且来自可信来源打开文件之前。做
  现在要打开文件吗?

"The file you are trying to open, 'filename.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"

如果我preSS'是'它的开放。我改变了文件扩展名的.xlsx,还是同样的信息。谁能告诉我为什么发生这种情况?我已经添加的.xlsx MIME类型扩展名在IIS管理器中使用MIME类型为应用程序/ vnd.openxmlformats-officedocument.s preadsheetml.sheet 。仍然它示出了同样的信息。请建议我怎么能摆脱掉它。

If I press 'Yes' it's opening. I changed the file extension to .xlsx, still same message. Can anyone tell me why this is happening? I've added .xlsx MIME type extension in IIS manager with MIME Type as application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. Still it's showing the same message. Please suggest how can I get rid off it.

推荐答案

你完全创建XLS文件或做你复制并填写模板xls文件?
不正确的格式模板文件可能会导致问题。

Do you completely create the xls file or do you copy and fill a template xls file ? An incorrect format template file may cause the problem.

此外,什么提供商,你用填写您的文件?
  - Microsoft.ACE.OLEDB.12.0为XLSX / XLSM?
  - ?Microsoft.Jet.OLEDB.4.0为XLS

Also, what provider do you use to fill your file ? - Microsoft.ACE.OLEDB.12.0 for xlsx/xlsm ? - Microsoft.Jet.OLEDB.4.0 for xls ?

这是不正确提供商/扩展组合可能会导致问题。

An incorrect provider/extension combination may cause the problem.

根据您的意见,这里是code,我已经做的一部分,在过去的:
(注释某些行,因为我不记得你为什么在这里有用)

According to your comment, here is a part of code where I have done that in the past : ( commented some of the lines as I don't remember why they where useful )

Response.Clear();                           
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentEncoding = Encoding.Default; 
//Response.Charset=""; 
Response.AddHeader("Content-Disposition: ",
    String.Format(@"attachment; filename={0}",myfileName));

//EnableViewState = false; 

Response.Write(myFileContentAsString); 
Response.Flush();
Response.Close();

这篇关于为什么出现错误消息,同时打开.xls文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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