}public enum ExportType {WORD,EXCELL }
public static void Export(string
htmlToExport, string filename,ExportType
eType)
{
filename =
HttpUtility.UrlDecode(filename);
string attachment =
string.Empty;
if (eType.ToString() ==
"WORD")
{
attachment = "attachment;filename=" + GetToExcelName(filename) +
".doc";
System.Web.HttpContext.Current.Response.ContentType =
"application/vnd.msword";
}
else
{
attachment = "attachment;filename=" + GetToExcelName(filename) +
".doc";
System.Web.HttpContext.Current.Response.ContentType =
"application/vnd.ms-excel";
}
System.Web.HttpContext.Current.Response.ClearContent();
System.Web.HttpContext.Current.Response.AddHeader("content-disposition",
attachment);
System.Web.HttpContext.Current.Response.ContentEncoding =
System.Text.Encoding.UTF8;
//page.Response.ContentEncoding =
page.Response.HeaderEncoding;
System.Web.HttpContext.Current.Response.Write(htmlToExport);
System.Web.HttpContext.Current.Response.End();
}
原文:http://www.cnblogs.com/jcz1206/p/3517796.html