[Vuejs]-How to change title font size for excel export Datatable?

0👍

This should work:

$("#datatable").DataTable({
      dom: "lBfrtip",
      buttons: [
        {
          extend: "excelHtml5",
          title: "Audit Trail Report",
          messageTop: `From ${this.start_date} To ${this.end_date}`,
          customize: function (xlsx) {
            var styles = xlsx.xl['styles.xml'];
            var fonts = $( 'fonts', styles );
            var newFontId = parseInt( fonts.attr( 'count' ) );
            fonts.attr( 'count', newFontId + 1 ).append( '<font><sz val="22"></sz><name val="Calibri"></name><b></b></font>' );
            var cellXfs = $( 'cellXfs', styles );
            var newStyleId = parseInt( cellXfs.attr( 'count' ) );
            cellXfs.attr( 'count', newStyleId + 1 ).append( '<xf numFmtId="0" fontId="' + newFontId + '" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1"><alignment horizontal="center"></alignment></xf>' );
                    
            var rowCount = 0;
            $( 'row', sheet ).each( function () {
                var row = this;
                if( rowCount == 0 ) {
                    $( 'c[r="A1"]', row ).attr( 's', newStyleId );
                }
                rowCount++;
            } );
          },
        },
        {
          extend: "pdf",
          title: "Audit Trail Report",
          messageTop: `From ${this.start_date} To ${this.end_date}`,
        },
      ],
      searching: false,
    })

Leave a comment