不同格式的jQuery数据表,如excel、pdf $('.dataTables示例').DataTable({ 页长:25, dom:“lTfgitp”, 按钮:[ {extend:'copy'}, {extend:'csv'}, {扩展:“excel”,标题:“ExampleFile”}, {extend:'pdfHtml5',title:'Product Information',messageTop:'Hi this is pdf message title options',messageBottom:'Footer pdf show'}, { 扩展:“打印”, 自定义:功能(win){ $(win.document.body).addClass('white-bg'); $(win.document.body).css('font-size','10px'); $(win.document.body).find('表') .addClass('compact') .css('font-size','inherit'); } } ] });

不同格式的jQuery数据表,如excel、pdf $('.dataTables示例').DataTable({ 页长:25, dom:“lTfgitp”, 按钮:[ {extend:'copy'}, {extend:'csv'}, {扩展:“excel”,标题:“ExampleFile”}, {extend:'pdfHtml5',title:'Product Information',messageTop:'Hi this is pdf message title options',messageBottom:'Footer pdf show'}, { 扩展:“打印”, 自定义:功能(win){ $(win.document.body).addClass('white-bg'); $(win.document.body).css('font-size','10px'); $(win.document.body).find('表') .addClass('compact') .css('font-size','inherit'); } } ] });,jquery,datatable,colors,background-color,Jquery,Datatable,Colors,Background Color,我正在以不同的格式从jQuery数据表导出数据,如excel、pdf。某些单元格在数据表中具有不同的背景色。但这些颜色不会显示在导出的excel或pdf中。有人能告诉我,如何解决这个问题吗?你可以像这样添加颜色 $('#示例')。数据表({ 页长:25, dom:“lTfgitp”, 按钮:[ {extend:'copy'}, {extend:'csv'}, {扩展:“excel”,标题:“ExampleFile”, 自定义:功能(xlsx){ var sheet=xlsx.xl.workshe

我正在以不同的格式从jQuery数据表导出数据,如excel、pdf。某些单元格在数据表中具有不同的背景色。但这些颜色不会显示在导出的excel或pdf中。有人能告诉我,如何解决这个问题吗?

你可以像这样添加颜色

$('#示例')。数据表({
页长:25,
dom:“lTfgitp”,
按钮:[
{extend:'copy'},
{extend:'csv'},
{扩展:“excel”,标题:“ExampleFile”,
自定义:功能(xlsx){
var sheet=xlsx.xl.worksheets['sheet1.xml'];
$('row:first c',sheet).attr('s','7');
$('row c[r^=“c”]”,第页)。每个(函数(){
$(this.attr('s','36');
});
}
},
]
});

解决方案对您有帮助吗?谢谢普密沙阿。它现在正在工作。但是我需要动态地为每个列添加不同的颜色。我的要求就像C、D、E和F列有多种颜色组合,如红色、黄色和绿色,并且根据一些规则需要在每个单元格中显示颜色。你能告诉我怎么做吗?
$('.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');
                    }
                }
            ]
        });
$('#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');
                                      });
                     }
                },
            ]
        });