AjaxPro2 导出数据到 Excel
网站程序是用 AjaxPro2 做的。有一个页面,页面上有一个按钮(导出到 Excel):
<input type="button" id="btnToExcel" value="导出到 Excel" onclick="ExportDataToExcel()" />
js脚本调用后台导出 Excel 的方法,后台 导出 Excel 的方法是:
public static void DataTableToExcel(System.Data.DataTable dt)
{
HttpResponse response = HttpContext.Current.Response;
string fileName = "MyReportDatas.xls";
response.ClearContent();
response.AddHeader("content-disposition", "attachment;filename=" + fileName);
response.ContentType = "application/excel";
response.ContentEncoding = System.Text.Encoding.UTF8;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
System.Web.UI.WebControls.GridView gvExport = new System.Web.UI.WebControls.GridView();
gvExport.HeaderStyle.Font.Bold = true;
gvExport.DataSource = dt;
gvExport.DataBind();
gvExport.RenderControl(htw);
response.Write("<meta http-equiv=Content-Type content='text/html; charset=utf-8'>");
response.Write(Environment.NewLine);
response.Write(sw.ToString());
response.End();
}
运行页面,点击 导出Excel 按钮后,出错:语法错误。
在 “core.ashx, 行29 字符153” 处出错 return eval('('+text+')')
请问如何解决?先谢谢了! --------------------编程问答--------------------
补充:.NET技术 , ASP.NET