How to export JavaScript array info to csv (on client side)?

前端 未结 29 1751
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 21:55

I know there are lot of questions of this nature but I need to do this using JavaScript. I am using Dojo 1.8 and have all the attribute info in array, which loo

29条回答
  •  春和景丽
    2020-11-21 22:46

    //It work in Chrome and IE ... I reviewed and readed a lot of answer. then i used it and tested in both ... 
    
    var link = document.createElement("a");
    
    if (link.download !== undefined) { // feature detection
        // Browsers that support HTML5 download attribute
        var blob = new Blob([CSV], { type: 'text/csv;charset=utf-8;' });
        var url = URL.createObjectURL(blob);            
        link.setAttribute("href", url);
        link.setAttribute("download", fileName);
        link.style = "visibility:hidden";
    }
    
    if (navigator.msSaveBlob) { // IE 10+
       link.addEventListener("click", function (event) {
         var blob = new Blob([CSV], {
           "type": "text/csv;charset=utf-8;"
         });
       navigator.msSaveBlob(blob, fileName);
      }, false);
    }
    
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    
    //Regards
    

提交回复
热议问题