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

下载代码如下:

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";

猜你喜欢

转载自www.cnblogs.com/chensong0524/p/12176110.html
今日推荐