Export HTML table to csv in google chrome browser

后端 未结 2 566
轻奢々
轻奢々 2020-12-08 23:10

i have following function by using this i am exporting my html to Csv file. few days/months ago it was working fine in google chrome browser (still its working fine

相关标签:
2条回答
  • 2020-12-09 00:03

    My solution is for excel file export:

    var xslData = new Blob([$('#printableSearchResults').html()], { type: 'text/vnd.ms-excel' });
    
    var uri = URL.createObjectURL(xslData);
    
    0 讨论(0)
  • 2020-12-09 00:17

    after doing some more research i got the solution for this.

    i have changed this

    var csvData ='data:application/csv;charset=utf-8,' + encodeURIComponent(dumpd);
    
    $(this)
        .attr({
        'download': filename,
            'href': csvData,
            'target': '_blank'
    });
    

    To

     var csvData = new Blob([dumpd], { type: 'text/csv' }); //new way
        var csvUrl = URL.createObjectURL(csvData);
    
        $(this)
        .attr({
            'download': filename,
            'href': csvUrl
        });
    

    and it worked fine. it seems chrome has changed something in new version.

    Hope it may help others.

    0 讨论(0)
提交回复
热议问题