Rav*_*nth 1 html javascript excel jquery datatables
我正在使用 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
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的 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>
Run Code Online (Sandbox Code Playgroud)
使用下面的代码:
$('<table>')
.append($(table.table().header()).clone())
.append(table.$('tr').clone())
.table2excel({
exclude: "",
name: "EmailTracking",
filename: "EmailTracking" //do not include extension
});
Run Code Online (Sandbox Code Playgroud)
请参阅此示例以获取代码和演示。