以前代码:
public static void htmlToExcel(HttpContext context, string title, string html, string fileCss = "", string SheetName = "")
{
var Response = context.Response;
string html1 = html;
Response.ContentType = "application/force-download";
Response.AddHeader("content-disposition", "attachment; filename=" + title + ".xls");
Response.Write("");
Response.Write("
");Response.Write("");
if (fileCss != "")
{
string cssText = string.Empty;
StreamReader sr = new StreamReader(fileCss);
var line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
cssText += line;
}
sr.Close();
Response.Write("");
}
Response.Write(" ");
Response.Write(html1);//HTML
Response.Flush();
Response.End();
}
public static void htmlToExcel(HttpContext context, string title, string html, string fileCss = "", string SheetName = "")
{
var Response = context.Response;
string html1 = html;
Response.ContentType = "application/force-download";
title = HttpUtility.UrlEncode(title, System.Text.Encoding.GetEncoding("UTF-8"));
Response.AddHeader("content-disposition", "attachment; filename=" + title + ".xls");
Response.Write("");
Response.Write("
");Response.Write("");
if (fileCss != "")
{
string cssText = string.Empty;
StreamReader sr = new StreamReader(fileCss);
var line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
cssText += line;
}
sr.Close();
Response.Write("");
}
Response.Write(" ");
Response.Write(html1);//HTML
Response.Flush();
Response.End();
}
给文件名通过转码的方式进行导出。
参考:http://blog.csdn.net/tongxinxiao/article/details/43733881