Javascript/ jQuery : Exporting data in CSV not working in IE

后端 未结 6 1456
太阳男子
太阳男子 2020-12-25 13:43

I need to Export Data displayed in a Table to CSV Format. I have tried lot many things but couldn\'t get it working for IE 9 and above.

I have created a dummy fiddle

6条回答
  •  梦毁少年i
    2020-12-25 14:13

    For IE 10+ you can do:

    var a = document.createElement('a');
            if(window.navigator.msSaveOrOpenBlob){
                var fileData = str;
                blobObject = new Blob([str]);
                a.onclick=function(){
                    window.navigator.msSaveOrOpenBlob(blobObject, 'MyFile.csv');
                }
            }
            a.appendChild(document.createTextNode('Click to Download'));
            document.body.appendChild(a);
    

    I don't believe it to be possible in earlier versions of IE. Without invoking the activeX object, but if that's acceptable you could use:

    var sfo=new ActiveXObject('scripting.FileSystemObject');
    var fLoc=sfo.CreateTextFile('MyFile.csv');
    fLoc.WriteLine(str);
    fLoc.close();
    

    Which would write the file directly to the user's file system. This will however generally prompt the user asking if they want to allow the script to run. The prompt can be disabled in an intranet environment.

提交回复
热议问题