[英]Datatables excel Export: Single Column type as text
I have been working on datatables jquery plugin and on exporting the datatable to excel, numbers in a particular column are displayed in the exponential notation. 我一直在研究datatables jquery插件,并将数据表导出到excel,特定列中的数字以指数表示法显示。 How can i convert the data to text for one column only? 如何仅将一列数据转换为文本?
By using exportOptions property of jquery datatable plugin you can restrict columns from exporting. 通过使用jquery datatable插件的exportOptions属性,可以限制列的导出。
$('#myTable').DataTable( {
buttons: [
{
extend: 'excelHtml5',
text: 'Save current page',
exportOptions: {
columns: 0,1,2 //it will exporting only 3 columns out of n no of columns
}
}
]
});
By using this you can avoid exporting of problematic column !! 通过使用这个可以避免导出有问题的列!
I found my way around this. 我找到了解决方法。 Here is what I did 这是我所做的
var table = $('#example').DataTable({
dom: 'BLfrtip',
pageLength: 50,
buttons: [{
extend: 'excel',
exportOptions: {
columns: ':visible'
},
Text: 'Export To Excel',
filename: 'Transaction Report',
customizeData: function (data) {
for (var i = 0; i < data.body.length; i++) {
for (var j = 0; j < data.body[i].length; j++) {
if (data.header[j] == "Column Name") {
data.body[i][j] = '\u200C' + data.body[i][j];
}
}
}
}}]});
This adds double quotes to each entry in the column 这会将双引号添加到该列中的每个条目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.