Excel output - possible to add "message" header using "customize" option?

Excel output - possible to add "message" header using "customize" option?

somehumansomehuman Posts: 7Questions: 2Answers: 0

With PDF and Print buttons there is a "message" option to put a header at the top of the output table. I use this to put the table caption into the exported PDF or Print output. It works great.

However, the Excel output does not support the "message" option. Is there a way to add that functionality using the "customize" option? I'm thinking that using the "customize" option, the XSLX can be modified somehow to duplicate the "message" function.

Does anyone have an example of this? It has to be a common thing people want...

Thanks

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    It is possible, but it probably won't be easy because you'd need to change the cell attributes for all the other cells that have been created (i.e. row 1 becomes row 2, etc).

    It might be easiest to put this functionality into the library rather than trying to do it externally. I've been thinking about doing that to match up with the PDF option. Can't promise it will be in the next release, but I will take a look!

    Allan

  • somehumansomehuman Posts: 7Questions: 2Answers: 0

    Allan:
    I played around with the code in /buttons/1.2.2/js/buttons.html5.js and think I found a solution. I added a section to the DataTable.ext.buttons.excelHtml5 function similar to that in the PDF function as follows:

    if ( config.message ) {
          var tablecaption = [config.message];
          addRow( tablecaption, rowPos );    // Add caption
          addRow( "", rowPos );              // Add blank row to separate the caption from the table data
            }
    

    and at the end of the DataTable.ext.buttons.excelHtml5, I added:

      message: null, 
    

    This allowed me to specify a message in the button config just like the PDF and Print buttons and have it appear as the top row of the Excel file output. Seems like a similar thing could be done for the csv maker code.

    Maybe this will help get it into the next release :wink:

    Thanks for your help
    Tim

  • somehumansomehuman Posts: 7Questions: 2Answers: 0

    I was right. It was super easy to add the message to the CSV and Copy output as well in the same /buttons/1.2.2/js/buttons.html5.js javascript file. With this you can specify a message parameter in the button config and it will appear at the top of the output with a blank line separating it from the datatable.

    in the _exportData function (they both use this function to format the output), add the following code just above where the data is returned from the function:

      if ( config.message ) {
          header = config.message + newLine + newLine + header;
        } 
    

    I also found out you don't need to add the message: null, code at the end of the various functions as I specified in my previous post.

    Again, hope this helps,
    Tim

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Hi Tim,

    Looks excellent - thanks for posting your solution. Buttons 1.2.3 was tagged yesterday, but I think this is a good option for the next release.

    Allan

This discussion has been closed.