【问题标题】:Datatable does not allow to include multiple footers rows into exported excel fileDatatable 不允许在导出的 excel 文件中包含多个页脚行
【发布时间】:2017-05-02 06:43:23
【问题描述】:

我正在尝试使用导出选项创建一个支持多个页脚的 Datatable Excel 文件。

但它只在单个单元格中创建页脚,不支持多行。

请告诉我是否可以在导出的 excel 文件中创建多行页脚?如果是,那么如何在javascript中实现?

或者是否有可能通过其他解决方法?

我正在分享代码

在 JavaScript 中创建数据表并在表中添加 tfoot

'<tfoot id="reportTblFoot' + chartIndex+ '">'+
'</tfoot>'

表格页脚变量

var footer1 = $("<tr />");

数据添加到页脚

footer1.append(
    "<th>" +
    "<div style='font-style:italic;font-size:10px'>" +
    "* Applicable row 1<br>\n" +
    "** Not Applicable row 2<br>\n" +
    "*** Not Applicable row 3\n" +
    "</div>" +
    "<div>" +
    "<font size='1' color='grey'>**** Not Applicable row 4</font>" +
    "</div>" +
    "</th>"
);

footer1.append("<th style='display:none'/>");
footer1.append("<th style='display:none'/>");

$(tfoot).append(footer1);

在数据表属性中为页脚应用 TRUE

buttons: [
{
extend: 'excel',
footer :true,
filename : fileName,
title : rprtTtl,
orientation: "landscape",
pageSize : "A3",
}]

【问题讨论】:

    标签: javascript excel datatable datatables datatables-1.10


    【解决方案1】:

    我找到了自己问题的解决方案

    这里我需要用新行 (\n) 替换数据,然后将其返回到页脚函数中。实际上,将数据传递到页脚是一种解决方法

     exportOptions : {
                    stripNewlines: false,
                    format : {
                             footer : function (data, column, row){
                             console.log(data.replace(/<br\s*[\/]?>/gi,'\n'));
                             return data.replace(/<br\s*[\/]?>/gi,'\n');
                                                                  }
                              }
                     },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-12
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 2015-08-02
      • 2019-04-08
      • 2013-09-13
      相关资源
      最近更新 更多