C#导出Excel,服务端已经生成Excel文件,不下载。
本人做了个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();