我正在尝试将Datatable导出到Excel工作表。 Datatable有一个带十进制值和%符号的列。导出后,十进制值将四舍五入。但是我需要带有%符号的十进制值才能出现在Excel工作表中。任何人都可以帮助我。谢谢。小提琴链接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>
答案 0 :(得分:0)
正确保存值,但数字格式设置为 0%,而不是 0.00%。
尝试在列上设置数字格式:
<td style='mso-number-format:"0.00%"'>99.021%</td>