下载的excel文件未以正确的格式显示 [英] Downloaded excel file is not showing in correct format

查看:109
本文介绍了下载的excel文件未以正确的格式显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我有一个.aspx页面,我已经给出了一个名为download的按钮控件,点击下载按钮,它将一个excel文件发送给浏览器download.On打开excel,它正确显示内容。





根据我的要求,我希望在同一页面上进行fileupload控制。我只是将fileupload控件拖放到设计页面并运行程序。现在,当我下载excel并打开它时,它显示文件不是可识别的格式。



如果我删除了fileupload控件,它工作正常。

可能是什么原因



点击按钮的代码如下

 < span class =code-keyword> protected   void  Button2_Click1( object  sender,EventArgs e )
{
string filePath = Label117.Text;
FileInfo file = new FileInfo(filePath);
if (file.Exists)
{
Response.Clear();

Response.ClearHeaders();

Response.ClearContent();

Response.AddHeader( Content-Disposition attachment; filename = + file.Name);

Response.AddHeader( Content-Length,file.Length。的ToString());

Response.ContentType = application / vnd.xls;

Response.Flush();

Response.TransmitFile(file.FullName);

Response.End();
}
}

解决方案

嗨Mahakaal,



如果您确定该扩展程序始终采用Excel格式,请按以下步骤进行修改:



 Response.AddHeader( Content-Disposition,attachment; filename =+ file.Name +。XML); 





您最后缺少Excel格式标签。



让我知道这是否对你有所帮助。



快乐编码...... :)



谢谢,

RelicV


 Response.ContentType =  应用/ XLS; 


Dear All,

I have a .aspx page where i have given a button control named download, on clicking download button it send an excel file to browser for download.On opening the excel it shows content properly.


As per my requirement i want fileupload control on the same page. I just dragged and dropped the fileupload control to design page and run the program. now when i download the excel and opens it,it shows the file is not in recognizable format.

if i removes the fileupload control, it works fine.
What can be the reason

Code on button click is as following

protected void Button2_Click1(object sender, EventArgs e)
       {
           string filePath = Label117.Text;
           FileInfo file = new FileInfo(filePath);
           if (file.Exists)
           {
               Response.Clear();

               Response.ClearHeaders();

               Response.ClearContent();

               Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

               Response.AddHeader("Content-Length", file.Length.ToString());

               Response.ContentType = "application/vnd.xls";

               Response.Flush();

               Response.TransmitFile(file.FullName);

               Response.End();
           }
       }

解决方案

Hi Mahakaal,

If you are sure that the extension is always in Excel format, then do the modification as follows:

Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name + ".XLS"); 



You are missing the Excel format tag at the end.

Let me know if this helped you or not.

Happy coding...:)

Thanks,
RelicV


Response.ContentType = "application/xls";


这篇关于下载的excel文件未以正确的格式显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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