在Internet Explorer中将数据从jqgrid导出到Excel

我正在开发一些网页的增强function,我需要一些帮助。 我添加了一个button,当点击将从一个jqgrid的HTML,并将其导出到Excel。 我以为我有这一切工作,然后我做了跨浏览器testing,Internet Explorer不喜欢以下方法:

function exportGrid() { var grid = "#diamondpassConferencePreregistrantGrid"; var mya=new Array(); mya=$(grid).getDataIDs(); // Get All IDs var data=$(grid).getRowData(mya[0]); // Get First row to get the labels var colNames=new Array(); var ii=0; for (var i in data){colNames[ii++]=i;} // capture col names var html=""; var columnNames = $(grid).jqGrid('getGridParam','colNames'); for(i=0;i<columnNames.length-1;i++) { html = html + columnNames[i+1]+"\t"; } html=html+"\n"; for(i=0;i<mya.length;i++) { data=$(grid).getRowData(mya[i]); // get each row for(j=0;j<colNames.length-1;j++) { html=html+data[colNames[j+1]]+"\t"; // output each column as tab delimited } html=html+"\n"; // output each row with end of line } html=html+"\n"; // end of line at the end alert(html); window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html)); } 

在Firefox和Chrome中,这一切似乎都适合我。 问题是,当我在IE中testing时,行:

  window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html)); 

打开一个新标签,告诉我该网页无法显示。

我从以下网页获得了一些信息:

http://www.jquerybyexample.net/2012/10/export-table-data-to-excel-using-jquery.html

基本上告诉我,行不能在IE中工作,我需要设置响应标题,如下所示:

 Response.AddHeader("Content-Disposition", "attachment;filename=download.xls"); 

我的问题是,我不知道这是什么。 我尝试添加这一行,正如我所期望的那样,我得到“Response is undefined”或者这种性质的东西。

我只是好奇,如果有人有一个想法,从这一点上最好的方式前进。 我知道如何检测浏览器,我总是可以使用不同的代码来完成我的IE浏览器的Excel导出,但我的问题是,我不知道在IE中做同样的行的正确方法。

任何帮助将不胜感激。

谢谢!

戴夫