jQuery 不同格式的数据表,如 excel、pdf
jQuery datatable in different formats like excel, pdf
$('.dataTables-example').DataTable({
pageLength: 25,
dom: '<"html5buttons"B>lTfgitp',
buttons: [
{ extend: 'copy' },
{ extend: 'csv' },
{ extend: 'excel', title: 'ExampleFile' },
{ extend: 'pdfHtml5', title: 'Product Information', messageTop: 'Hi this is pdf message title options', messageBottom: 'Footer PDF show' },
{
extend: 'print',
customize: function (win) {
$(win.document.body).addClass('white-bg');
$(win.document.body).css('font-size', '10px');
$(win.document.body).find('table')
.addClass('compact')
.css('font-size', 'inherit');
}
}
]
});
我正在以 excel、pdf 等不同格式从 jQuery datatable 导出数据。某些单元格在数据 table 中具有不同的背景颜色。但这些颜色未显示在导出的 excel 或 pdf 中。谁能告诉我,如何解决这个问题?
你可以这样添加颜色https://jsfiddle.net/fj80vtur/1/
$('#example').DataTable({
pageLength: 25,
dom: '<"html5buttons"B>lTfgitp',
buttons: [
{ extend: 'copy' },
{ extend: 'csv' },
{ extend: 'excel', title: 'ExampleFile',
customize: function (xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:first c', sheet).attr('s', '7');
$('row c[r^="C"]',sheet).each(function(){
$(this).attr('s', '36');
});
}
},
]
});
$('.dataTables-example').DataTable({
pageLength: 25,
dom: '<"html5buttons"B>lTfgitp',
buttons: [
{ extend: 'copy' },
{ extend: 'csv' },
{ extend: 'excel', title: 'ExampleFile' },
{ extend: 'pdfHtml5', title: 'Product Information', messageTop: 'Hi this is pdf message title options', messageBottom: 'Footer PDF show' },
{
extend: 'print',
customize: function (win) {
$(win.document.body).addClass('white-bg');
$(win.document.body).css('font-size', '10px');
$(win.document.body).find('table')
.addClass('compact')
.css('font-size', 'inherit');
}
}
]
});
我正在以 excel、pdf 等不同格式从 jQuery datatable 导出数据。某些单元格在数据 table 中具有不同的背景颜色。但这些颜色未显示在导出的 excel 或 pdf 中。谁能告诉我,如何解决这个问题?
你可以这样添加颜色https://jsfiddle.net/fj80vtur/1/
$('#example').DataTable({
pageLength: 25,
dom: '<"html5buttons"B>lTfgitp',
buttons: [
{ extend: 'copy' },
{ extend: 'csv' },
{ extend: 'excel', title: 'ExampleFile',
customize: function (xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:first c', sheet).attr('s', '7');
$('row c[r^="C"]',sheet).each(function(){
$(this).attr('s', '36');
});
}
},
]
});