17

I'm creating a csv file for download using Javascript and it's working perfectly fine in everything except for IE (I've tested 8 and 10).

In IE8, when I click the button to create and download the file I get an error that comes up and says "The data area passed to a system call is too small". In IE10, when I click the button it just opens a new tab that has the URL I've created in the address bar but doesn't download anything.

Any ideas what this error means?

I have this code in a button:

var csvContent = "data:text/csv;charset=utf-8,";
csvContent += escape(myCSVvariable);

var encodedUri = encodeURI(csvContent);
window.open(encodedUri);

This is related to this question but I started a new one because I got a different error after changing some things - How do I create and download a csv file using Javascript?

Rachel Gallen
  • 25,819
  • 19
  • 69
  • 75
Jack Hillard
  • 536
  • 10
  • 24

2 Answers2

25

This is a known issue, but there is a workaround.

Add the following code

if (navigator.msSaveBlob) 
{ // IE 10+ 
navigator.msSaveBlob(new Blob([csv], { type: 'text/csv;charset=utf-8;' }), "filename.csv"); 
}

and the issue should be resolved. This works for IE10, I have not tested it on IE8 (I don't have IE8 anymore!)

Refer to:

https://msdn.microsoft.com/library/Hh772331

https://msdn.microsoft.com/library/Hh772298

Source

Rachel Gallen
  • 25,819
  • 19
  • 69
  • 75
3

There is a size restriction of URL in IE.

Alex Shilman
  • 1,529
  • 1
  • 11
  • 15
  • 1
    @nipiv: Consider to write api and then you post all the content to the server through http. From the server, write a logic to handle the data from client and export the csv file. Normally you will need to do something with the respond and Content-Disposition header. Take a look at https://goosedotnet.wordpress.com/2014/09/29/generate-and-export-a-string-only-csv-file-from-webapi/ – trungk18 Jun 30 '17 at 08:26
  • Well we already had a solution where the backend wud create the excel, but i was looking for a for a frontend solution. i found some libraries like xlsz.js which does the trick. But we have gone back to a backend downlodable solution. – nipiv Jun 30 '17 at 14:24