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 = {


  • allanallan Posts: 48,464Questions: 1Answers: 7,020 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' );


  • Dalex73Dalex73 Posts: 30Questions: 4Answers: 4

    Perfect, thanks!

Sign In or Register to comment.