导出html页面 EXCEL

//导出html页面
        public void OutPutExcel(string title)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "utf-8";

            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(title + ".xls"));
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");

            Response.ContentType = "application/ms-excel";
            Page.EnableViewState = false;

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

            this.Page.RenderControl(oHtmlTextWriter);

            string temp = oStringWriter.ToString();
           
            Response.Write(temp);//写入excel
            Response.End();
        }

posted on 2011-03-07 17:54  mingfeng  阅读(398)  评论(0编辑  收藏  举报

导航