(急.....)怎样将查询出来的数据导出为EXCEL文件??? 如题.我要先将查询出来的数据显示在Gridview控件中,然后导出为EXCEL文件.查询出来的每一笔数据的字段不一样,我应该怎样实现上面的功能,谢谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static void GenerateByGridView(string Typename, GridView TempGrid) { HttpContext.Current.Response.Clear(); //HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Charset = "utf-8"; string Filename = Typename + ".xls"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "online;filename=" + Filename); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); HttpContext.Current.Response.ContentType = "application/ms-excel"; //this.EnableViewState = false; System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); TempGrid.RenderControl(oHtmlTextWriter); HttpContext.Current.Response.Write(oStringWriter.ToString()); HttpContext.Current.Response.End(); }Typename 为文件名 请参考这篇文章:http://dotnet.aspx.cc/article/700bd3fa-a17f-41dc-b258-0dc572625700/read.aspx 我试了glacier111(★冰河★)给出来的代码,但运行时有如下错误,不知道什么原因,还请各位大虾赐教!错误 No overload for 'btn_output_Click' matches delegate 'System.EventHandler' 讨论一下代码和UI的分离 怎么才可以把一个表中的起始时间加上另一个表中的天数查询出来? div的定位问题 求论文名,顶者有分 一个简单问题请大家帮忙! 要命的dbgrid,怎么才能在单元格内插入图片? sql语句中时间的比较!!!!!!!!!!! 在线等待,div 定位的问题. 请教有关按钮事件的调用? 如何把DataGri输出到EXCEL里 DataGrid中DropDownList问题 关于 httpmodule 事件可以响应的请求文件类型。
{
HttpContext.Current.Response.Clear();
//HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "utf-8";
string Filename = Typename + ".xls";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "online;filename=" + Filename);
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.ContentType = "application/ms-excel";
//this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
TempGrid.RenderControl(oHtmlTextWriter);
HttpContext.Current.Response.Write(oStringWriter.ToString());
HttpContext.Current.Response.End();
}Typename 为文件名
http://dotnet.aspx.cc/article/700bd3fa-a17f-41dc-b258-0dc572625700/read.aspx