jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 如何在数据表中的excel导出文件中添加空行或自定义标题?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
谁能告诉我如何在数据表中导出excel文件添加一些空白行?

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

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

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

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

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

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,buttons: [
        $.extend( true,{},buttonCommon,{
            extend: 'copyHtml5'
        } ),$.extend( true,{
            extend: 'excelHtml5'
        } ),{
            extend: 'pdfHtml5'
        } )
    ]
} );

谢谢高级朋友.

解决方法

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

在下面的代码之前,下载并存储1.2.2版的文件.你可以在这里找到链接version 1.2.2 link并下载文件//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">

我更改了行号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
    }

我非常感谢以下链接
@L_197_42@

$('#invoice_data').DataTable({
    ordering: true,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',customize: function ( doc ) {
                            doc.content.splice( 0,{
                                text: "custom header\n my header"
                            } );
            }
        }

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

});

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

大佬总结

以上是大佬教程为你收集整理的jquery – 如何在数据表中的excel导出文件中添加空行或自定义标题?全部内容,希望文章能够帮你解决jquery – 如何在数据表中的excel导出文件中添加空行或自定义标题?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。