码迷,mamicode.com
首页 > Windows程序 > 详细

C# Web 下载excel文件后直接导入下载的文件报错的问题

时间:2020-01-10 15:54:50      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:缓存   binary   ade   osi   问题   导入   clear   app   style   

下载代码如下:

System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + outputFileName);
System.Web.HttpContext.Current.Response.BinaryWrite(oByte);
//清除缓存
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.End();

上面标红的代码为出错的关键所在,应改为:

System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";

C# Web 下载excel文件后直接导入下载的文件报错的问题

标签:缓存   binary   ade   osi   问题   导入   clear   app   style   

原文地址:https://www.cnblogs.com/chensong0524/p/12176110.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!