黑马程序员技术交流社区
标题:
Repeater导出Excel的通用过程
[打印本页]
作者:
唐煜婷
时间:
2011-12-5 09:19
标题:
Repeater导出Excel的通用过程
private void ToExcel(ref System.Web.UI.WebControls.Repeater rp, string filename)
{
filename = System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Buffer = true;
System.Web.HttpContext.Current.Response.Charset = "gb2312";
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "online; 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);
rp.RenderControl(oHtmlTextWriter);
rp = null;
System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString().Replace("<td", "<td STYLE='MSO-NUMBER-FORMAT:\\@'"));
System.Web.HttpContext.Current.Response.Buffer = false;
System.Web.HttpContext.Current.Response.End();
}
复制代码
作者:
王伟
时间:
2011-12-5 17:33
看不懂{:soso_e134:},写点注释!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2