Why Download to xls feature doesn't work in Edge browser, but works in chrome

谁都会走 提交于 2019-12-25 18:45:39

问题


Below is my code for download to xls feature. I am not sure why its not woking in Edge. However , it works fine in chrome. There are no console errors too. Not sure which part of the below of line of code is not supported in Edge. Is there any other way to rewrite the below code so that it supports edge.

 $scope.downloadXls = function() {
    var repayments = $scope.repayments;
    var csvContent = "data:text/csv;charset=utf-8,";

    var rows = [
      [
        "Payment No",
        "Installment", 
        "Principal", 
        "Interest", 
        "Balance", 
      ]
    ];

    for (var i = 0; i < repayments.length; i++) {
      rows.push([
        i + 1,
        parseFloat(repayments[i].installment).toFixed(2),
        parseFloat(repayments[i].principal).toFixed(2),
        parseFloat(repayments[i].interest).toFixed(2),
        parseFloat(repayments[i].balance).toFixed(2)
      ]);
    }
    rows.forEach(function(rowArray) {
        let row = rowArray.join(",");
        csvContent += row + "\r\n";
    });

    var encodedUri = encodeURI(csvContent);
    var link = document.createElement("a");
    link.setAttribute("href", encodedUri);
    link.setAttribute("download", "repayment_schedule.csv");
    document.body.appendChild(link); // Required for FF
    link.click();
  }

来源:https://stackoverflow.com/questions/59177227/why-download-to-xls-feature-doesnt-work-in-edge-browser-but-works-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!