- 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();
- }
复制代码 |