【发布时间】:2018-04-30 17:49:15
【问题描述】:
我正在尝试通过使用来自 jquery 数据表的按钮扩展的 attr('s', '20') 将样式应用于 excel。 https://datatables.net/reference/button/excelHtml5 下面的代码是我如何将样式应用于一行的第三个孩子:
$('#DataTable').DataTable({
dom: 'Bfrtip',
buttons: [
{
extend: 'excelHtml5',
customize: function (xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row[r!=1]', sheet).each(function () {
$(this).children().eq(2).attr('s', '20');//apply style to 3rd child of the row.
});
}
}]...............
问题是:当单元格为空时,样式不会被应用。
当第三个单元格为空字符串或数据表中的 null 时,该样式将不适用于 excel 文件。我调试了代码,发现当单元格为空字符串时 $(this).children().eq(2) 不存在。如果第三个单元格中有一些文本,则将应用该样式。
有谁知道如何解决这个问题?或者有没有办法将样式应用于整行。
谢谢。
【问题讨论】:
-
您是否尝试过像这样直接设置行的样式:
$('row[r!=1]', sheet).attr( 's', '20' )? -
我刚试过。它没有用。基于datatables.net/reference/button/excelHtml5,内置样式仅适用于单元格。
标签: jquery excel datatables