如何在数据表中的excel导出文件中添加空行或自定义标题?

Jim*_*mil 5 datatable jquery

谁能告诉我如何在数据表中导出excel文件中添加一些空白行?

我正在尝试将标题添加到excel文件中,我尝试了很多方法,但它们都没有为我工作.

如果没有人知道怎么做,提示如何在excel中添加空行也对我有用.

我现在的简单代码如下,我想知道我可以添加什么来使它适用于excel导出,因为我已经找到了pdf和csv的解决方案,但不是excel文件的解决方案:

$('#invoice_data').dataTable( {
    ordering: true,"autoWidth": false,
    paging: true,
    searching: true,
    dom: 'Bftripl',
    buttons: [
        'excelHtml5',
        'csvHtml5',
        'pdfHtml5'
    ]
});
Run Code Online (Sandbox Code Playgroud)

以下是另一个尝试,我试图添加空行但它不起作用:

var buttonCommon = {
    exportOptions: {
        format: {
            header: function ( data, row, column, node ) {
                // Strip $ from salary column to make it numeric
                return column === 1 ?
                    "llll "+row+" nd "+node :
                    data+"KKK "+row+" nd "+node;
            }
        }
    }
};
 $('#invoice_data').DataTable({
    ordering: true,"autoWidth": false,
    paging: true,
    searching: true,
    dom: 'Bftripl',
    buttons: [
        $.extend( true, {}, buttonCommon, {
            extend: 'copyHtml5'
        } ),
        $.extend( true, {}, buttonCommon, {
            extend: 'excelHtml5'
        } ),
        $.extend( true, {}, buttonCommon, {
            extend: 'pdfHtml5'
        } )
    ]
} );
Run Code Online (Sandbox Code Playgroud)

谢谢高级朋友.

Jim*_*mil 8

所以最后我找到了解决方案,所以我的代码能够将标题放在数据表中的Excel,PDF,CSV文件中.因为我发现很难找到答案,所以我将代码放在这里.这样任何人都可以使用它.

在下面的代码之前,下载并存储1.2.2版的文件.你可以在这里找到链接:版本1.2.2链接和下载文件//cdn.datatables.net/buttons/1.2.2/js/buttons.html5.js

因此,在我的DataTable代码之前放置以下代码行(我将上面的下载文件放在js文件夹中,然后重命名为"buttons_export_config_header.js"):

<script type="text/javascript" src="../js/buttons_export_config_header.js">
Run Code Online (Sandbox Code Playgroud)

我更改了行号1129到1131,我在上面的文件中放了以下代码:

if ( config.header) {
         var tablecaption = [config.message];
  addRow( tablecaption, rowPos );
         //addRow( "testing", "0" );
          addRow( "", rowPos );
        addRow( data.header, rowPos );
        //$('row c', rels).attr( 's', '2' ); // bold
    }
Run Code Online (Sandbox Code Playgroud)

我非常感谢以下链接: datatables post

$('#invoice_data').DataTable({
    ordering: true,"autoWidth": false,
    paging: true,
    searching: true,
    dom: 'Bftripl',
    buttons: [
    {
            extend: 'excelHtml5',

            title: 'Any title for file',
            message: "Any message for header inside the file. I am not able to put message in next row in excel file but you can use \n"


        },
        {
            extend: 'csvHtml5',
            title: 'Any title for the file',
             customize: function (csv) {
                 return "Any heading for the csv file can be separated with , and for new line use \n"+csv;
              }
        },
        {
            extend: 'pdfHtml5',
            title: 'Any title for file',
            customize: function ( doc ) {
                            doc.content.splice( 0, 0, {
                                text: "custom header\n my header"
                            } );
            }
        }

        //'excelHtml5',
        //'csvHtml5',
        //'pdfHtml5'
    ] 

}); 
Run Code Online (Sandbox Code Playgroud)

我很高兴我自己找到了解决办法.:)