Reputation: 23
I am trying to export Datatable to excel sheet. Datatable has a column with decimal values and % symbol. After exporting, the decimal values are getting rounded off. But I need decimal values with % symbol to be present in the excel sheet. Can anyone help me with it. Thanks. fiddle link https://jsfiddle.net/xevpdeo1/23/
$(document).ready(function() {
var xlsBuilder = {
filename: 'business-group-sharers-',
sheetName: 'business-group-sharers-',
exportOptions: {
columns: [0, 1, 2, 3, 5]
}
}
$('#example').DataTable({
dom: 'Bfrtip',
buttons: [
$.extend(true, {}, xlsBuilder, {
extend: 'excel'
})
]
});
});
<table id="example" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Percentage</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Percentage</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Jonas Alexander</td>
<td>Developer</td>
<td>San Francisco</td>
<td>30</td>
<td>2010/07/14</td>
<td>99.021%</td>
</tr>
<tr>
<td>Shad Decker</td>
<td>Regional Director</td>
<td>Edinburgh</td>
<td>51</td>
<td>2008/11/13</td>
<td>87.96%</td>
</tr>
<tr>
<td>Michael Bruce</td>
<td>Javascript Developer</td>
<td>Singapore</td>
<td>29</td>
<td>2011/06/27</td>
<td>77.77%</td>
</tr>
<tr>
<td>Donna Snider</td>
<td>Customer Support</td>
<td>New York</td>
<td>27</td>
<td>2011/01/25</td>
<td>92.07%</td>
</tr>
</tbody>
</table>
Upvotes: 1
Views: 1370
Reputation: 2125
The values are saved correctly, but the number format is set to 0% instead of 0.00%.
Try to set the number format on columns:
<td style='mso-number-format:"0.00%"'>99.021%</td>
Upvotes: 0