public static void gridToExcel(System.Web.UI.WebControls.DataGrid grid, string excelName)
{  
HttpContext.Current.Response.Charset ="GB2312";
HttpContext.Current.Response.ContentEncoding =   System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=" + excelName + ".xls");
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");  grid.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
grid.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}