[英]How to export a table with header to Excel with table2excel
我正在使用table2excel將由jQuery DataTables支持的數據表導出到Excel。 我可以將數據導出到excel,但不能導出帶有標題的表。
這是我的代碼
$('#btn-export').on('click', function () {
$('<table>').append(table.$('tr').clone()).table2excel({
exclude: "",
name: "EmailTracking",
filename: "EmailTracking" //do not include extension
});
});
這是我的HTML:
<table id="userGrid" class="table table-striped table-bordered dt-responsive nowrap " cellspacing="0" width="100%">
<thead>
<tr>
<th>User</th>
<th>Subject</th>
<th>Sent On</th>
<th>To</th>
<th>Cc</th>
<th>Bcc</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
使用以下代碼:
$('<table>')
.append($(table.table().header()).clone())
.append(table.$('tr').clone())
.table2excel({
exclude: "",
name: "EmailTracking",
filename: "EmailTracking" //do not include extension
});
有關代碼和演示,請參見此示例 。
將您的html代碼更改為以下代碼:
<table id="userGrid" class="table table-striped table-bordered dt-responsive nowrap "
cellspacing="0" width="100%">
<thead>
<tr>
<td><b>User</b></td>
<td><b>Subject</b></td>
<td><b>Sent On</b></td>
<td><b>To</b></td>
<td><b>Cc</b></td>
<td><b>Bcc</b></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.