dynamic sheetName?

dynamic sheetName?

Dalex73Dalex73 Posts: 30Questions: 4Answers: 4

Hi @allan

Is there any way to set a dynamic name for the sheetName option? I have modified the buttons code to allow for a function in the same way as filename/title. Is this one way of solving it (as it works for me) or can/is it done in any other way?

 "sheetName" : function( d ) {
              return $('#dropdown option:selected').text().trim().substring(0,31);
 },

The changes to buttons js file is,

    var _sheetname = function (config) {

        var sheetName = config.sheetName;

        if (typeof sheetName === 'function') {
            sheetName = sheetName().replace(/[\[\]\*\/\\\?\:]/g, '');
        }

        return sheetName;
    };

Then I just added sheetName: 'Sheet1', above filename: '*', under DataTable.ext.buttons.excelHtml5 = {

Replies

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    You would need to use the customize callback of the excelHtml5 button type and customize the sheet name as you need:

    $( 'sheets sheet', xlsx.xl['workbook.xml'] ).attr( 'name', 'New name' );
    

    Allan

  • Dalex73Dalex73 Posts: 30Questions: 4Answers: 4

    Perfect, thanks!

This discussion has been closed.