Excel正在重现空数据

Excel正在重现空数据

本文介绍了Excel正在重现空数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
                               "attachment; filename=" + Session["NwAccountName"] + "_" + DateTime.Now +
                               "_DestinationUrlsReport.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            var sw = new StringWriter();
            var hw = new HtmlTextWriter(sw);
            GridView1.AllowPaging = false;
            GridView1.DataBind();
            GridView1.RenderControl(hw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

推荐答案

Response.ContentType = "application/ms-excel";


而不是

Response.ContentType = "application/vnd.ms-excel";


您需要添加这些行


and you need to add these lines

Response.ContentEncoding = System.Text.Encoding.UTF8;
             Response.Cache.SetCacheability(HttpCacheability.NoCache);



并删除



and remove the

Response.Flush();



让我知道它是否有效...



Let me know if it works...



这篇关于Excel正在重现空数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 22:54