posts - 69, comments - 46, trackbacks - 0, articles - 1
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

2006年5月9日

private void ToExcel(System.Web.UI.Control ctl)
    {
 Response.Charset = "GB2312";
   Response.AppendHeader("Content-Disposition", "attachment;filename=" +
System.DateTime.Now.ToString("yyyyMMddhhmmss") + "_" +
HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes("表格")) + ".xls");
 Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/ms-execl";
ctl.Page.EnableViewState = false;
 System.IO.StringWriter tw= new System.IO.StringWriter();
 System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);
  ctl.RenderControl(hw);
   Response.Write(tw.ToString());
  Response.End();
   }

posted @ 2006-05-09 23:58 God Blue Shadow 阅读(462) 评论(2) 编辑