Excel export throwing error in MS excel

Excel export throwing error in MS excel

simark95simark95 Posts: 6Questions: 3Answers: 0
buttons: [ {
            extend: 'excelHtml5',
            title: '',
            customize: function( xlsx ) {
  
                var sheet = xlsx.xl.worksheets['sheet1.xml'];
                $('row c', sheet).each( function () {
  
                    if ( $('is t', this).text().indexOf("http") === 0 ) {
                        $(this).append('<f>' + 'HYPERLINK("'+$('is t', this).text()+'","'+$('is t', this).text()+'")'+ '</f>');
                        $(this).attr( 's', '2' );
                    }
                });
                }
        } ],

I am trying to convert text to hyperlinks in excel so that they are clickable directly. These are image URLs from the table that get converted to plain text when i open the sheet. The above snippet throws an error in MS office.

It seems that my modification to the text to hyperlink has broken the parsing. Unsure why but it opens up fine in WPS and google sheets.

I have attached the excel that is causing an issue.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    You've asked this once already - please don't repeat threads.

    As I said in that thread:

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • simark95simark95 Posts: 6Questions: 3Answers: 0
    edited February 2020

    @colin https://jsfiddle.net/j4czp5b0/4/
    Sorry for the duplicate, I wasn't sure about the fiddle. Managed to replicate it now.
    Please click on the export product button and you will notice the error while opening the file in MS excel. Comment that customize function and it works fine.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Yep, it's the customize function - it looks like you're trying to create links with the URLs. This thread should help, it's asking the same thing.

    Colin

  • simark95simark95 Posts: 6Questions: 3Answers: 0

    @colin Since I want to add some custom data into the cell (in this case a URL) would $(this).append('cell data to be replaced') be correct ?? Because the .append() method inserts the specified content as the last child of the element. I followed some of the stuff posted on that thread but nothing is mentioned about replacing data in the cell.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    I would suggest using orthogonal data for that - so the data is exported with the appended information already. There's an example of that here.

    Colin

This discussion has been closed.