gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:00:27 26 4
gpt4 key购买 nike

如何在数据表导出的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,"autoWidth": false,
paging: true,
searching: true,
dom: 'Bftripl',
buttons: [
$.extend( true, {}, buttonCommon, {
extend: 'copyHtml5'
} ),
$.extend( true, {}, buttonCommon, {
extend: 'excelHtml5'
} ),
$.extend( true, {}, buttonCommon, {
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
}

我非常感谢以下链接: 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'
]

});

我很高兴自己找到了解决方案。:)

关于jquery - 如何在数据表的Excel导出文件中添加空白行或自定义标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46106160/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com