Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download BLOB content using specified charset

Is possible to change the Blob charset really? I'm trying it for hours but it doesn't workds. See this.

jQuery("#download").click(function() {     var csv_content = jQuery("#csv").val(),         download = document.createElement("a"),         blob = new Blob([csv_content], { type: "text/csv;charset=ISO-8859-1" });      download.href = window.URL.createObjectURL(blob);     download.download = "test.csv";      var event = document.createEvent("MouseEvents");     event.initMouseEvent(         "click", true, false, window, 0, 0, 0, 0, 0         , false, false, false, false, 0, null     );     download.dispatchEvent(event);     }); 

I need export a CSV to open on Excel, but it always is save with UTF-8 and Excel can't handle it.

like image 961
David Rodrigues Avatar asked Sep 20 '13 20:09

David Rodrigues


1 Answers

I found the solution before to post.

The change of charset has not been resolved, in fact. However, I sent the UTF-8 header for the download process and Excel was able to understand the file format correctly. Thanks to this response of Erik Töyrä.

blob = new Blob(["\ufeff", csv_content]); 
like image 116
David Rodrigues Avatar answered Sep 22 '22 17:09

David Rodrigues