Problem with jQuery Datatables Buttons - Excel Export - Using Special Character like "&" or "<" - Page 2

Problem with jQuery Datatables Buttons - Excel Export - Using Special Character like "&" or "<"

2»

Answers

  • ZoneZone Posts: 4Questions: 0Answers: 0

    Thank you. Had the same issue, disabling the stripHtml solved it:

     buttons: [
             'copy', 
            {
               extend: 'excel', 
               title: 'Export',
               exportOptions: {
                    stripHtml: false  
                }
            },
            { extend: "remove", editor: editor }
      ]
    
  • mabsmabs Posts: 3Questions: 0Answers: 0

    @allan
    Hy Allan i'm using Following Libraries:
    DataTables 1.10.16, Buttons 1.4.2, Column visibility 1.4.2, Flash export 1.4.2, HTML5 export 1.4.2, Print view 1.4.2, ColReorder 1.4.1, Select 1.2.3. etc.
    I'v got the same Problem with the stripping of Special Characters for the Excel Export Buttons.
    After trying your latest fix for this Problem with the "stripHtml : false" Options it seems that this Option doesn´t work me unfortunately....
    Do you have any other Solutions for this Problem except an manual replace for every affected Special Char ?

    Thank you in advanced

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin

    Can you link to a page showing the issue please?

    Allan

  • mabsmabs Posts: 3Questions: 0Answers: 0
    edited February 2018

    @allan
    {
    extend : 'excel',
    exportOptions : {
    stripHtml : false,
    modifier : {
    selected : true
    },
    //Export only visible Data
    columns: ':visible:not(:first-child)',
    format: {
    //Format Export Data to keep seperator
    body: function(data, row, column, node) {
    var href;
    try {
    var $href = $(data);
    href = $href.attr('href');
    } catch(error){};
    data = (typeof href != 'undefined' && href.search(/.pdf$/) > 0) ? href.slice(href.lastIndexOf('/') + 1) : data;
    return $.isNumeric(data.replace(',', '.')) ? data.replace(',', '.') : data.replace(/<([^>]+)>/ig, "");
    }
    }
    },
    className : 'btn btn-default btn-xs',
    text : '<i class="fa fa-fw fa-download"></i> als Excel exportieren'
    },

    After Exporting to Excel and opening the Requested File the "&" is replaced by "&"

  • mabsmabs Posts: 3Questions: 0Answers: 0

    ....& is replaced by & amp ;

  • dpskdpsk Posts: 3Questions: 1Answers: 0

    Have the exact issue with both excel and pdf export, did you find a solution @mabs ?

  • beachcm65beachcm65 Posts: 22Questions: 6Answers: 0

    I'm having part of the html show in the Excel export. Here is a link to the table ->click on the Authors tab on the left and then click the Excel export button.

    In Excel, when I scroll about a third of the way down (row 1082), I begin to see entries like this: Career Publications: N/A"" class=""simple-tooltip"">YOUSSEF, CAROLYN M.

    I think I'm using the latest versions of everything.

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    The HTML in your data is badly formed.

    Career Publications: 161, 2009-2018">
    

    That closing tag has no corresponding opening tag.

  • beachcm65beachcm65 Posts: 22Questions: 6Answers: 0

    Thanks tangerine - I only showed a snippet. Here is the whole row. You could visit the page if you're interested in the whole table. The snippet is inside of a title attribute and the whole thing is in quotes. I'm no html guru so let me know if this is incorrect.

     <tr>
        <td><span class="simple-tooltip" title="Recent Affiliation: N/A<br>
    Career Publications: N/A"><a href="https://app.dimensions.ai/discover/publication?facet_researcher=ur.014062240435.10" target="_blank">YOUSSEF, CAROLYN M.</a></span></td>
        <td align=center>1</td>
        <td align=center>1</td>
        <td align=center>6</td>
        <td align=center>0</td>
        <td align=center>2007</td>
        <td align=center>Unfunded</td>
        <td align=center>1</td>
        <td align=center></td>
        <td align=left>N/A</td>
      </tr>
    

    There is a newline after the <br> in the span title. I thought maybe this was causing the issue, but I get the same error with or without the newline.

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    I visited your page, checked your data, and gave you the answer.
    Run your page through a HTML validator if you want a second opinion.

  • beachcm65beachcm65 Posts: 22Questions: 6Answers: 0

    Thanks tangerine. You helped put me on the right track. From another post, I found that using a <br> tag within the title tag was the issue. Removing the <br> tag gives me a clean Excel export.

This discussion has been closed.