0

I have customized the excel in datatable with number format using jQuery, it's working fine but when I added the background color, number format is removed, cannot add a multiple style at a time.

This is my js code

$('#summary-table').DataTable({
        "ajax": {
            "url": "/summary-report",
        },
        "columns": [
            {"data": "start_balance"},
            {"data": "total_redeems"},
        ],
        dom: 'Blfrtip',
        "footerCallback": function (tfoot, data, start, end, display) {
        var api = this.api();
        var intVal = function(i) {
            return typeof i === 'string' ?
                i.replace(/[\$,]/g, '') * 1 :
                typeof i === 'number' ?
                    i : 0;
        };
        var sp = api.column(2).data().reduce(function (a, b) {
            return intVal(a) + intVal(b);
        }, 0)
        var sTotal = new Number(sp).toLocaleString("LKR");
        $(api.column(2).footer()).html(" " +sTotal);
       
    },
    buttons: [
        {
            extend: "excel",
            className: "btn excel",
            footer:true,
            filename: function () {
                return "MovementSummary_Report";
            },
            title: 'System',
            customize : function (xlsx) {
                var sheet = xlsx.xl.worksheets['sheet1.xml'];
                var numberFormat = ['B'];
                for ( i=0; i < numberFormat.length; i++ ) {
                    $('row:eq(-1) c[r^='+numberFormat[i]+']', sheet).attr( 's', '63' );  
                    $('row:eq(-1) c[r^='+numberFormat[i]+']', sheet).attr( 's', '17' );  
                }
            },
            messageTop: function () {
                return (
                    "Movement Summary | " +
                    MEMBER_SUMMARY_REPORT_SELECTED_DATE_RANGE
                );
            },
        },
        
    ],
});
  • That is correct - you can only apply one of the [built-in styles](https://datatables.net/reference/button/excelHtml5#Built-in-styles) at a time. You cannot combine them. – andrewJames Aug 02 '21 at 13:19
  • You can create your own custom styles. You can see something similar [here](https://stackoverflow.com/a/67340599/12567365), which shows how to create a custom number format - but it does also include the creation of a basic custom style. – andrewJames Aug 02 '21 at 13:19

0 Answers0