使用ASP.NET打开Excel文件 [英] Open a Excel file using ASP.NET

查看:237
本文介绍了使用ASP.NET打开Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用VS 2008开发ASP.NET应用程序.我已经通过代码生成了一个Excel文件并将其保存在服务器上.我使用了以下代码.

Hi,
I am working on an ASP.NET application using VS 2008. I have generated an Excel file through code and saved it on the server. I have used the following code.

Response.ContentType = "Excel";
      Response.AppendHeader("Content-Disposition", "attachment; filename=Report.xls");
      Response.TransmitFile(Server.MapPath("~//Report.xls"));
      Response.End();



最后,它工作正常,但是当我在服务器上发布站点时,它没有打开文件.而是显示消息找不到页面".

请帮忙!



On my end, it works fine but when I publish the site on the server, it doesn''t open the file. Instead it gives the message "Page not found".

Please help!

推荐答案

错误在这里:

The error lies here:

Response.TransmitFile(Server.MapPath("~//Report.xls"));



访问文件的URL格式不正确.有时,托管后,文件的路径与开发中的路径有些许不同.

尝试使用此提示 [



The URL to access the file is not forming correctly. At times, after hosting, the path of files are a little different than while in development.

Try using this tip[^] for resolving the URLs.


这篇关于使用ASP.NET打开Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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