我希望有人能让我走上正轨。我需要将 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();
}