Complex headers export to Excel

Complex headers export to Excel

shankarastashankarasta Posts: 14Questions: 6Answers: 0

Hi Allan,

Is any new info on exporting complex headers to Excel?
If we still have to wait for V2, is there a work around?

Thanks,

Answers

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

    No - the is no workaround (other than adding the feature and submitting it as a pull request :)).

    Currently, yes, you need to wait until I get a chance to work on this.

    Allan

  • shankarastashankarasta Posts: 14Questions: 6Answers: 0

    Hi Allan,

    So I found the following changes made to the buttons plugin at
    https://github.com/rstudio/DT/issues/418

    I download his code and replaced button buttons.html5.min.js and dataTables.buttons.min.js.
    It works as desired and multi-level headers get exported correctly.

    Hope this helps, looks like an easy change until V2 comes out.

    Thanks,
    Shankar

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

    Awesome - thanks for posting that link.

    Allan

  • shankarastashankarasta Posts: 14Questions: 6Answers: 0

    Hi Allan,

    Any update on this issue?
    Is it still an open issue?

    Thanks,

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

    Correct, this is still an open issue. I've afraid I've not had a chance to work on this yet.

    Allan

  • einarameinaram Posts: 1Questions: 0Answers: 0

    I read about kind of a workaround that might help someone else.

    Merges the complex header to single line:

    http://jsfiddle.net/RajReddy/jzdjdo3z/21/

  • ManiDhoniManiDhoni Posts: 10Questions: 0Answers: 0

    Hi Allan,

    Any update on this issue?
    Is it still an open issue?

    Thanks,

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

    Still an open issue I’m afraid. Not something I’ve worked on yet.

    Allan

  • Shivani VyasShivani Vyas Posts: 113Questions: 11Answers: 0

    @allan Hi allan is there any update on this issue ? Is there any plugins available that I am not aware about it. Please let me know.

    My current temporary solution:

      extend: 'excelHtml5',
       text: 'export to Excel',
       customize: function (xlsx) {
    
           //copy _createNode function from source
           function _createNode(doc, nodeName, opts) { 
               var tempNode = doc.createElement(nodeName);
    
               if (opts) {
                   if (opts.attr) {
                       $(tempNode).attr(opts.attr);
                   }
    
                   if (opts.children) {
                       $.each(opts.children, function (key, value) {
                           tempNode.appendChild(value);
                       });
                   }
    
                   if (opts.text !== null && opts.text !== undefined) {
                       tempNode.appendChild(doc.createTextNode(opts.text));
                   }
               }
    
               return tempNode;
           }
    
           var sheet = xlsx.xl.worksheets['sheet1.xml'];
           var mergeCells = $('mergeCells', sheet);
           mergeCells[0].children[0].remove(); // remove merge cell 1st row
    
           var rows = $('row', sheet);
           rows[0].children[0].remove(); // clear header cell
    
           // create new cell
           rows[0].appendChild(_createNode(sheet, 'c', {
               attr: {
                   t: 'inlineStr',
                   r: 'B1', //address of new cell
                   s: 51 // center style - https://www.datatables.net/reference/button/excelHtml5
               },
               children: {
                   row: _createNode(sheet, 'is', {
                       children: {
                           row: _createNode(sheet, 't', {
                               text: 'new header text'
                           })
                       }
                   })
               }
           }));
    
    
           // set new cell merged
           mergeCells[0].appendChild(_createNode(sheet, 'mergeCell', {
               attr: {
                   ref: 'B1:E1' // merge address
               }
           }));
    
           mergeCells.attr('count', mergeCells.attr('count') + 1);
    
           // add another merged cell
       }
    
  • allanallan Posts: 61,694Questions: 1Answers: 10,102 Site admin

    No updates I'm afraid - sorry. It is something that will be part of the DataTables 2 work. I'll be making an announcement when it is available, but it is not something that I have progressed with yet.

    Allan

Sign In or Register to comment.