user3679149
user3679149

Reputation: 81

Export in CSV from JSON in IE through javascript

How to download table rows in CSV format in Internet Explorer from client side? At present I am using the below URI method to download it in other browser. But it seems Internet Explorer does not support the below mechanism. I want to support from IE version 8 till the latest. Any help for IE would be appreciated.

   var fileName = "Result"; 
   var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);
   var link = document.createElement("a");    
   link.href = uri;
   link.style = "visibility:hidden";
   link.download = fileName + ".csv";
   document.body.appendChild(link);
   link.click();
   document.body.removeChild(link);

Upvotes: 2

Views: 3563

Answers (1)

user3679149
user3679149

Reputation: 81

I got the solution for it which is supporting IE 8+ for me. We need to specify the separator as shown below.

if (navigator.appName == "Microsoft Internet Explorer") {    
    var oWin = window.open();
    oWin.document.write('sep=,\r\n' + CSV);
    oWin.document.close();
    oWin.document.execCommand('SaveAs', true, fileName + ".csv");
    oWin.close();
  }  

You can go through the link http://andrew-b.com/view/article/44

Upvotes: 1

Related Questions