将表格标题中的HTML表格导出到带有ID或类别标记的Excel中

我在我的网页上有一个HTML表格,当使用JQuery将它导出到Excel时,如果表头中有任何id或class标记,它将不起作用。

我正在使用的JQuery是

//wont work unless the table has no class or id $("#btnExport").click(function (e) { window.open('data:application/vnd.ms-excel,' + $("#tableForExcel").html()); e.preventDefault(); }); 

我正在使用的表是

 <table id='SearchTable' class='table table-bordered table-striped table-hover table blue '> <tr> <th class='ReportManager'>Report Manager</th> <th class='ReportDetail'>Report Detail</th> <th class='Form'>Form</th> </tr> <tr> <td class='ReportManager'></td> <td class='ReportDetail'></td> <td class='Form'></td> </tr> <tr> <td class='ReportManager'></td> <td class='ReportDetail'></td> <td class='Form'></td> </tr> </table> 

我将不胜感激,如果你能帮助我\让我看看我应该如何调整我的代码,以得到这个出口。

我已经用这种方法解决了这个问题:

 $("#btnExport").click(function (e) { window.open('data:application/vnd.ms-excel,' +'<table>' +$("#SearchTable").html()+ '</table>'); e.preventDefault(); }); 

我希望它可以帮助你。