0

I am using ngCsv module https://github.com/asafdav/ng-csv.

It's not working in IE9. Some suggests in below code to work in IE9 but for me its not working.

see the link Data URI scheme and Internet Explorer 9 Errors

link: function (scope, element, attrs) {
    function doClick() {
      var charset = scope.charset || "utf-8";
      var blob = Blob !== undefined ? new Blob([scope.csv], {
        type: "text/csv;charset="+ charset + ";"
      }) : '';

      if ( navigator.userAgent.toLowerCase().match(/msie/gi) || navigator.appName.match(/Internet/gi) || navigator.msMaxTouchPoints !== void 0 ){ 
          if( window.navigator.msSaveOrOpenBlob ) {
              navigator.msSaveBlob(blob, scope.getFilename());
          }else{
            var iframe = angular.element('<iframe></iframe>');
            iframe[0].style.display = "none";
            element.append(iframe);
            var doc = null;
            if (iframe[0].contentDocument) 
                doc = iframe[0].contentDocument;
            else if (iframe[0].contentWindow) 
                doc = iframe[0].contentWindow.document;
            doc.open("text/plain", "replace");
            doc.write([decodeURIComponent(scope.csv)]);

            //iframe.focus();
            doc.execCommand('SaveAs', true, scope.getFilename());
            doc.close();
          }

      } else {

        var downloadLink = angular.element('<a></a>');
        downloadLink.attr('href', window.URL.createObjectURL(blob));
        downloadLink.attr('download', scope.getFilename());
        downloadLink.attr('target', '_blank');

        $document.find('body').append(downloadLink);
        $timeout(function () {
          downloadLink[0].click();
          downloadLink.remove();
        }, null);
      }
    }

Here console.log(doc.execCommand('SaveAs', true, scope.getFilename())); returning false.

And see the link ngcsv - Trouble in safari and IE Browsers There is no support for IE9.

Please someone provide me a solution or suggest me any other way to download(array or Object) CSV content from browser in AngularJS.

Thanks in advance.

Community
  • 1
  • 1
Hemakumar
  • 639
  • 9
  • 24

1 Answers1

-1

Long time issue but here's a solution if anyone still needs it.

Hopefully they will merge this soon for all of us.

https://github.com/asafdav/ng-csv/issues/151

lcampanis
  • 49
  • 2