簡體   English   中英

使用表頭中的ID或類標記將HTML表導出到Excel

[英]Export HTML Table to Excel with ID or class tags in the table header

我在我的網頁上有一個HTML表格,當使用JQuery將其導出到Excel時,如果表頭中有任何id或類標簽,它將無法工作。

我正在使用的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();
});

我希望它對你有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM