62,046
社区成员
发帖
与我相关
我的任务
分享
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = Encoding.GetEncoding("gb2312");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.GetEncoding("gb2312")).ToString());
this.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView gv = new GridView();
gv.DataSource = dt;// 这里是你的数据源 (如:DataTable,DataSet)
gv.DataBind();
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();