更改具有所需类的列的数据表excel导出中excel文件的单元格背景

问题描述 投票:0回答:1

如何更改具有所需类的列的数据表excel导出中Excel文件中单元格背景的颜色,比如说我有一个类名= .error

基本上,我需要突出显示所需的单元格,例如在验证失败的excel文件中将backgrounf颜色更改为红色。但由于不知道该怎么做而苦苦挣扎。]

例如,我接受了此代码。

$(document).ready(function() {
    $('#example').DataTable({
        dom: 'Bfrtip',
        buttons: [{
            extend: 'excelHtml5',
            customize: function(xlsx) {
                var sheet = xlsx.xl.worksheets['sheet1.xml'];

                // Loop over the cells in column `C`
                $('row c[r^="C"]', sheet).each( function () {
                    // Get the value
                    if ( $('is t', this).text() == 'New York' ) {
                        $(this).attr( 's', '20' );
                    }
                });
            }
        }]
    });
});

这里,我可以知道我们正在循环遍历sheet1的每个单元格并检查该单元格是否包含文本“ New York”,因此,类似地,我想知道如何更改具有名为.error类的任何单元格的背景色。

jquery excel datatables
1个回答
0
投票
如何使用hasClass()?

$(document).ready(function() { $('#example').DataTable({ dom: 'Bfrtip', buttons: [{ extend: 'excelHtml5', customize: function(xlsx) { var sheet = xlsx.xl.worksheets['sheet1.xml']; // Loop over the cells in column `C` $('row c[r^="C"]', sheet).each( function () { // Get the value if ( $(this).hasClass( "error" )) { $(this).Css( 'background-color', 'red' ); } }); } }] }); });

© www.soinside.com 2019 - 2024. All rights reserved.