JSON To CSV / XLS Does Not Save A File On IE
I have the following service: angular.module('LBTable').service('exportTable', function () { function JSONToCSVConvertor(JSONData, ReportTitle, ShowLabel, fileName) { /
Solution 1:
the Reason is IE doesn't support the download attribute in a tag. The work around is you can Use blob
Convert the JSON to CSV
Check the current browser for that you can use the below code
getInternetExplorerVersion() {
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
else if (navigator.appName == 'Netscape') {
var ua = navigator.userAgent;
var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
return rv;
}
- if the browser is IE
var blob = new Blob([CSV], { type: "text/csv;charset=utf-8;" });
navigator.msSaveBlob(blob, fileName + ".csv")
This will work in IE
Post a Comment for "JSON To CSV / XLS Does Not Save A File On IE"