C#导出Excel,服务端已经生成Excel文件,不下载。

我就叫Vieso 我就叫Vieso 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
本人做了个C#导出Excel的功能,
架构师用的EasyUI,Jq去访问的后台,后台已经生成所需的Excel,但是页面就是不提示下载,哪位大侠知道,不妨指点一二。
以下是输出的代码:

System.Web.UI.Page page = new System.Web.UI.Page();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.ContentEncoding = Encoding.Default;
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + page.Server.UrlEncode(fileInfo.Name));
//HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileInfo.Name);
HttpContext.Current.Response.WriteFile(fileInfo.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();


fileInfo.FullName是文件在服务器上的物理路径,已经确认路径是对的了。
后台的Excel也已经生成。
其实这也能算是文件不能下载的问题。
请各位大侠多指教
...全文

相关推荐

评论 16
收藏 已收藏
分享
返回顶部
我就叫Vieso
C# 111,130 成员 642,541 内容