下载代码如下:
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";
原文地址:https://www.cnblogs.com/chensong0524/p/12176110.html