Excel正在重现空数据 [英] Excel is returing empty data
本文介绍了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();
推荐答案
我认为您需要按以下方式更改行
I think you need to change the line as below
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...
代码似乎还可以,请尝试以下两种方法:
1-注释该行-Response.Flush();
2-使用Response.Write(sw.ToString());代替
Response.Output.Write(sw.ToString());
让我知道怎么回事...
The code seems to be ok, try these two things:
1- Comment the line - Response.Flush();
2- Use Response.Write(sw.ToString()); in place of
Response.Output.Write(sw.ToString());
Let me know how it goes...
这篇关于Excel正在重现空数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文