[HttpPost]
public ActionResult ExportTableToExcel(string htmlTable)
{
EFWPResponse Result = new EFWPResponse() { RequestStatus = false };
try
{
Response.AppendHeader("content-disposition", "attachment;filename=FileEName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
//this.EnableViewState = false;
Response.Write(htmlTable);
Response.End();
}
catch (Exception ex)
{
ModelState.AddModelError("", ex);
}
return Json(Result);
}
//代码执行成功但没有打开excel文件。 //可以通过jquery在C#中生成用于生成Excel文件的任何正文。