如何将table控件导出到excel? 如何将table控件导出到excel? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Response.ContentType = "application/vnd.ms-excel"; Response.Charset = ""; this.EnableViewState = false; System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw); GridView1.RenderControl(hw); Response.Write(sw.ToString()); Response.End(); public static void ExportExcel(GridView GridView1, string title) { title = title + "<br><br>"; string strHtml = ""; System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.Buffer = true; System.Web.HttpContext.Current.Response.Charset = "UTF-8"; System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls"); System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel"; System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true); System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); GridView1.RenderControl(oHtmlTextWriter); strHtml = oStringWriter.ToString(); strHtml = title + strHtml; System.Web.HttpContext.Current.Response.Write(strHtml); System.Web.HttpContext.Current.Response.End(); } WCF如何动态配置地址 正则表达式关键字匹配问题 winform--如何找到界面上的所有label 在线等... 请问 如何在cs文件中弹出对话框 然后根据用户选择 执行不同的数据库操作? 如何用程序来生成ISO文件 一个算法问题。 TableLogonInfo值不能为空,用水晶报表,前边查询FILL他的XSD数据集,同时显示GRID;然后在另外一个按钮中打印,怎么取不出数据来啊? 谁用过XtraGrid这个东西,进来帮帮忙. 服务版本更新的问题 问一个很原始的问题,大家别笑话我 关于POP画面的传值问题 为什么那都没写错怎么读数据读的是2
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
public static void ExportExcel(GridView GridView1, string title)
{
title = title + "<br><br>";
string strHtml = ""; System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Buffer = true;
System.Web.HttpContext.Current.Response.Charset = "UTF-8";
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
GridView1.RenderControl(oHtmlTextWriter); strHtml = oStringWriter.ToString();
strHtml = title + strHtml; System.Web.HttpContext.Current.Response.Write(strHtml);
System.Web.HttpContext.Current.Response.End();
}