//记得不能用ajax 请求 | submit 和服务器按钮都可以
//sbHtml div 内容
//fileName 导出来后文件名
public static void Export(StringBuilder sbHtml, string fileName)
{
try
{
if (sbHtml.Length > 0)
{
HttpContext.Current.Response.ContentType = “application/vnd.ms-excel”;
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.Charset = “Utf-8”;
HttpContext.Current.Response.AppendHeader(“Content-Disposition”, “attachment;filename=” + HttpUtility.UrlEncode(fileName + “.docx”, System.Text.Encoding.UTF8));
HttpContext.Current.Response.Write(sbHtml.ToString());
HttpContext.Current.Response.End();
}
}
catch (Exception ex)
{
Logger.WriteLog(“———–导出数据异常———–\r\n” + ex.ToString() + “\r\n”);
}