将GridView数据直接导出为EXCEL(保留样式),适用GV不分页的情况

Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            Response.Charset = "";

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

            System.IO.StringWriter tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);


            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("统计.xls", System.Text.Encoding.UTF8));
            gvData.RenderControl(hw);

            Response.Write(tw.ToString());
            Response.End();
posted @ 2014-07-25 17:18  裸奔的豆子  阅读(178)  评论(0编辑  收藏  举报