我希望有人能讓我走上正確的軌道。我需要下載我的Gridview到Excel:Gridview到Excel不會在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();
}
除了一些格式化問題,我已經解決了,看看我的問題http://stackoverflow.com/questions/17251162/gridview-export-to-excel-formatting-problems,有一種方法工作正常導出datagrid excel。 – FeliceM