我希望有人能让我走上正确的轨道。我需要下载我的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