首先这个 不能用ajax 操作,不过 我现在讲的 这个方法和ajax 的效果一样。
你在你需要导出的页面写个方法
function DaoChu ()
{
location.href = "DaoChu.aspx";
}
然后在 DaoChu.aspx 页面的后台Page_Load 中 直接写以下代码
string html = "
1 | 11 |
2 | 22 |
Response.ContentType = "application/force-download";
Response.AddHeader("content-disposition",
"attachment; filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
Response.Write("");
Response.Write("
");Response.Write("");
string fileCss = Server.MapPath("~/css/daoChuCSS.css");
string cssText = string.Empty;
StreamReader sr = new StreamReader(fileCss);
var line = string.Empty;
while (