gpt4 book ai didi

javascript - 如何使用 table2excel 将带标题的表格导出到 Excel

转载 作者:行者123 更新时间:2023-11-28 18:29:11 25 4
gpt4 key购买 nike

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

参见this example用于代码和演示。

关于javascript - 如何使用 table2excel 将带标题的表格导出到 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38473833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com