private static void WriteToExcelFromDataGrid(DataGrid dg, string fileName)
{

StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
dg.RenderControl(hw);

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8");//正确utf-7,utf-8不支持中文
response.ContentType ="application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
response.Charset = "gb2312";
response.Write(tw.ToString());
response.End();
}

相关文章:

  • 2021-12-31
  • 2021-09-11
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-10-06
猜你喜欢
  • 2022-12-23
  • 2021-07-31
  • 2021-05-24
  • 2021-06-08
  • 2022-12-23
  • 2021-10-06
  • 2021-08-28
相关资源
相似解决方案