Gridview导出Excel的问题:
单击打开后,在Excel中弹出对话框
无法找到“C:\Documents and Settings\Administrator\Local Settings\Teporary Internet Files\Content.IE5\ENWZGHW9\Excel[1].xls”.
但是如果点击保存就可以正常打开,打开后的Excel和GridView中的内容和样式都是一样的。
请高手指点!
单击打开后,在Excel中弹出对话框
无法找到“C:\Documents and Settings\Administrator\Local Settings\Teporary Internet Files\Content.IE5\ENWZGHW9\Excel[1].xls”.
但是如果点击保存就可以正常打开,打开后的Excel和GridView中的内容和样式都是一样的。
请高手指点!
protected void To_excel_Click(object sender, EventArgs e)
{
GridViewAllInfo.AllowPaging = false;
GridViewAllInfo.AllowSorting = false;
UserAllInfo(); //绑定gridview的方法
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=Excel.xls;");
Response.ContentType = "application/excel"; StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridViewAllInfo.RenderControl(htw); Response.Write(sw.ToString());
Response.End();
}
Excel的直接打开的保存位置不知道在哪里改,所以savefile()的代码加在哪里!!!谢谢
但是我在自己机器上又重新做了一个小程序绑定gridview,再导出Excel就成功了。百思不得其解啊!
可以先尝试换掉文件类型看看, 比如用text/html, 文件名也写成.htm 如果这样可以直接打开就能证实这一点.建议修改修改IE的缓存目录的位置, 或者把IE升级试试.