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

将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();