[C#] 导出Excel, 使用页面table →→→→→进入此内容的聊天室

来自 , 2021-04-29, 写在 C#, 查看 126 次.
URL http://www.code666.cn/view/40173ea4
  1.  
  2. public static void ExportExcel(string FileName, StringBuilder table)
  3.         {
  4.             HttpContext.Current.Response.ClearContent();
  5.             HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流的字符集
  6.             HttpContext.Current.Response.Charset = "gb2312";
  7.             HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName));
  8.  
  9.             HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
  10.             StringWriter sw = new StringWriter(table);
  11.             //HtmlTextWriter htw = new HtmlTextWriter(sw);
  12.  
  13.             //Page page = new Page();
  14.             //page.EnableEventValidation = false;
  15.             //page.DesignerInitialize();
  16.             //page.RenderControl(htw);
  17.             HttpContext.Current.Response.Write("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=gb2312\"/>" + sw.ToString());
  18.             HttpContext.Current.Response.Flush();
  19.             HttpContext.Current.Response.End();
  20.         }

回复 "导出Excel, 使用页面table"

这儿你可以回复上面这条便签

captcha