1

Im trying to export String data to CSV using unicode in JavaScript using UTF-8 and \uFEFF. The problem is when the CSV file build he take the string after comma , and the first cell filled with this string : "Content-Disposition:attachment;filename="+filename+"\ ," " . I tried to change the position of the charset to the end, but the fileName must be in the end of the link.

Any ideas ?

thanks!

downloadCampaingnCsv: function(campaignIds,filename, url){

                  var s = new Server();
                  var response = s.sendJSON(ApiBaseUrl +  url,'POST',campaignIds);
                  var csvContent = "data:text/csv;charset=utf-8,/uFEFF;Content-Disposition:attachment;filename="+filename+"\ ," ;     
                  if (response != "No Data!"){
                    var encodedUri = csvContent +encodeURI(response); 
                  } else {
                    var encodedUri  = "data:text/csv;filename="+filename+"\ ,"  + encodeURI(response);
                  }
                  var link = document.createElement("a");
                  link.setAttribute("href", encodedUri);
                  link.setAttribute("download", filename);
                  link.click();
   }
user3520259
  • 11
  • 1
  • 3

1 Answers1

2

the answer is in this link Javascript to csv export encoding issue the bottom line is "data:attachment/csv;charset=utf-8,%EF%BB%BF" + {{yuourCsvString}};

Community
  • 1
  • 1