导出Excel

Response.Clear();
   Response.Buffer = true;
   Response.Charset = "gb2312";
   Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode("中文名称") + ".xls");
   //Response.ContentEncoding = System.Text.Encoding.Default;

   Response.ContentType = "application/ms-excel";

   this.EnableViewState = false;

   System.IO.StringWriter oStringWriter = new StringWriter();
   System.Web.UI.HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);

   this.RenderControl(oHtmlTextWriter);
   Response.Write(oStringWriter.ToString());
   Response.End();

posted @ 2007-03-02 15:18  RobotTech  阅读(207)  评论(0编辑  收藏  举报