- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在数据表导出的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/
我正在使用 LinqToExcel 轻松地将 Excel 数据导入 SQL Server。 var fileName = ConfigurationManager.AppSetting
在我的 MVVM WPF 应用程序中,我使用的是数据绑定(bind)流文档。我使用了 here 描述的技术能够将我的数据绑定(bind)到流文档。 我的流文档绑定(bind)到我的 View 模型中的
好吧,这很难解释。 场景: 我有一个 DataGrid 定义如下: 它有两个 header ,我需要添加数据,我做了很多研究建议使用 Obs
如果用户单击 DataGridView 底部的空白行并将焦点从 DataGridView 移开,则现在单击的行将处于指示对该行进行更改的状态。 是否可以告诉 DataGridView 取消将此行标记为
我必须迭代行并将其添加到列表中,但我得到的总行数是 Excel 工作表中存在的总行数,即 1001 行,但我只有 3 行,包括标题,我必须停止使用行号的大小进行循环。 我的代码是 Sheet
我有一个 csv 文件,其中包含必须从中删除的信息(通过删除相应的列来完成),我得到的输出是我所期望的,除了每行之间还给我空白行。我怎样才能摆脱那些? (我目前没有pandas,所以如果有解决这个问题
我是一名优秀的程序员,十分优秀!