Generate CSV file from javascript under IE11

后端 未结 1 453
花落未央
花落未央 2020-12-20 07:48

I read lot of sample to generate csv file from data and push it to download to export it.

 let csvContent = \'\';
                $.each(msg.d.LstObj[0], fun         


        
相关标签:
1条回答
  • 2020-12-20 08:36

    Here is the block I use to satisfy all browsers, IE 11 included and it works great for me:

    if (window.navigator.msSaveBlob) {
        //Internet Explorer
        window.navigator.msSaveBlob(new Blob([result]), csvFileName);
    } else if (window.webkitURL != null) {
        //Google Chrome and Mozilla Firefox
        var a = document.createElement("a");
        result = encodeURIComponent(result);
        a.href = "data:application/csv;charset=UTF-8," + result;
        a.download = csvFileName;
        a.click();
    } else if (navigator.appName === "Microsoft Internet Explorer") {
        //Internet Explorer 8 and 9
        var oWin = window.open();
        oWin.document.write("sep=,\r\n" + result);
        oWin.document.close();
        oWin.document.execCommand("SaveAs", true, csvFileName);
        oWin.close();
    } else {
        //Everything Else
        window.open(result);
    }
    
    0 讨论(0)
提交回复
热议问题