【问题标题】:jQuery datatable in different formats like excel, pdf不同格式的jQuery数据表,如excel,pdf
【发布时间】:2018-06-08 07:57:18
【问题描述】:
$('.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 数据表中导出数据。某些单元格在数据表中具有不同的背景颜色。但是这些颜色没有显示在导出的 excel 或 pdf 中。谁能告诉我,如何解决这个问题?

【问题讨论】:

  • 解决方案对您有帮助吗?
  • 谢谢布米沙阿。它现在正在工作。但是我需要动态地为每一列添加不同的颜色。

标签: jquery datatable colors background-color


【解决方案1】:

你可以像这样添加颜色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');
                                      });
                     }
                },
            ]
        });

【讨论】:

  • 我的要求是 C、D、E 和 F 列有多种颜色组合,如红色、黄色和绿色,并且根据某些规则需要在每个单元格中显示颜色。你能告诉我如何动态地做到这一点吗?
猜你喜欢
  • 1970-01-01
  • 2022-12-21
  • 2015-07-04
  • 1970-01-01
  • 1970-01-01
  • 2019-03-16
  • 1970-01-01
  • 2018-08-13
  • 1970-01-01
相关资源
最近更新 更多