【发布时间】:2013-06-26 04:24:02
【问题描述】:
我希望有人能让我走上正轨。我需要将我的 Gridview 下载到 Excel:
Gridview 毫无问题地出现在我的 .ascx 页面上...我按下按钮执行以下代码,我收到保存或打开的提示,但随后我发现“file.xls”不在格式正确或损坏,我按 OPEN ... 我的 Excel 中没有出现任何内容。我记得以前必须这样做,但我遇到了麻烦......我错过了什么:
protected void dwnLoad(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=kbNotification.xls");
Response.Charset = "";
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWriter);
Response.End();
}
【问题讨论】:
-
除了我已经解决的一些格式问题,看看我的问题stackoverflow.com/questions/17251162/…,有一种方法可以很好地将数据网格导出到excel。