///
        /// 导出Excel
        ///
        ///
        ///
        public static void Data2Excel(System.Web.UI.Control ctl,string filename)
        {
            HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+filename);
            HttpContext.Current.Response.Charset ="";               
            HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.GetEncoding("utf-8");
            HttpContext.Current.Response.ContentType ="application/vnd.ms-excel";
            ctl.Page.EnableViewState =false;           
            System.IO.StringWriter  tw = new System.IO.StringWriter() ;
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
            ctl.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
        }
posted on 2006-09-08 08:13  过江  阅读(392)  评论(1编辑  收藏  举报