I'm using table2excel to export a datatable powered by jQuery DataTables to Excel. I am able to export the data to excel but i am not able to export table with the heading.
Here is my code
$('#btn-export').on('click', function () {
$('<table>').append(table.$('tr').clone()).table2excel({
exclude: "",
name: "EmailTracking",
filename: "EmailTracking" //do not include extension
});
});
Here is my 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>
I'm using table2excel to export a datatable powered by jQuery DataTables to Excel. I am able to export the data to excel but i am not able to export table with the heading.
Here is my code
$('#btn-export').on('click', function () {
$('<table>').append(table.$('tr').clone()).table2excel({
exclude: "",
name: "EmailTracking",
filename: "EmailTracking" //do not include extension
});
});
Here is my 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>
Share
Improve this question
edited Jul 20, 2016 at 14:35
Gyrocode.
59k16 gold badges156 silver badges192 bronze badges
asked Jul 20, 2016 at 6:29
Ravi KanthRavi Kanth
1,21014 silver badges41 bronze badges
2
- Better to use Jasper Report. – Ryan Commented Jul 20, 2016 at 7:12
- datatables/forums/discussion/28188/… – Ryan Commented Jul 20, 2016 at 7:14
2 Answers
Reset to default 5Use the code below:
$('<table>')
.append($(table.table().header()).clone())
.append(table.$('tr').clone())
.table2excel({
exclude: "",
name: "EmailTracking",
filename: "EmailTracking" //do not include extension
});
See this example for code and demonstration.
change your html code to this code:
<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>