我正在使用datatables.net从表中导出csv文件,如下所示:
var buttonCommon = {
exportOptions: {
format: {
body: function (data, row, column, node) {
return data.replace("\"", "");
}
}
}
};
<%--Data tables--%>
var table = $('.table').DataTable({
"paging": false,
"ordering": false,
"info": false,
"searching": false,
bSortCellsTop: false,
dom: 'Bfrtip',
buttons: [
$.extend(true, {}, buttonCommon, {
extend: 'csvHtml5'
})
]
});
这应该导致csv文件中没有双引号,但它们却显示...。 我查看了却找不到任何人遇到此问题?有什么想法我做错了吗?
"Receipt","Total","Date","","","","Total","Type","GL Code","Amount","","",""
"g092920","","09/29/2020","","","","","","106.104.0000","$37.52","","",""
"","","","","","","","","106.369.0009","$0.00","","",""
"g092920","","09/29/2020","","","","","","","$0.00","","",""
"g092920","","09/29/2020","","","","","","106.208.1000","$2.45","","",""
"g092920","","09/29/2020","","","","","","106.347.2040","$20.07","","",""
"g092920","","09/29/2020","","","","","","106.347.2050","$0.00","","",""
"g092920","","09/29/2020","","","","","","106.347.2050","$15.00","","",""
答案 0 :(得分:2)
这就是您要停止在字符串周围使用双引号的所有方法,请注意fieldBoundary选项:
var table = $('.table').DataTable({
"paging": false,
"ordering": false,
"info": false,
"searching": false,
bSortCellsTop: false,
dom: 'Bfrtip',
buttons: [
$.extend(true, {}, buttonCommon, {
extend: 'csvHtml5',
fieldBoundary: ''
})
]
});