5

I am trying hebrew csv file using javascript on Chrome extension.

But I got failed string.

enter image description here

Here is my code snippet.

var csv = "Phone\nאני אוהב אותך\n";
var file = new Blob([csv], {type: 'text/csv;utf-8'});
var url = URL.createObjectURL(file);
chrome.downloads.download({
    url: url,
    filename: name
}, function() {
    URL.revokeObjectURL(msg.url);
});
6
  • Are you setting the charset to utf-8? cant' tell by this code. Commented Jun 22, 2017 at 13:17
  • where should I set? Commented Jun 22, 2017 at 13:21
  • "var file = new Blob([csv], {type: 'text/csv;utf-8'});" so yes, to me it seems that it is set. Commented Jun 22, 2017 at 13:27
  • Just to test and not as a real solution, but if you use the following url: utf8-chartable.de/unicode-utf8-table.pl?start=1280 and use the codes in the first column of the table (like א for Aleph etc), is the output correct in that case or not? Commented Jun 22, 2017 at 13:28
  • Actually, @DanielvanDommele it's not the obvious. According to this: stackoverflow.com/questions/19492846/… it should be set as following: "data:text/csv;charset=utf-8 Commented Jun 22, 2017 at 14:10

2 Answers 2

2

Try this:

var csv = String.fromCharCode(0xFEFF) + "Phone\nאני אוהב אותך\n";  // <--- here
var file = new Blob([csv], {type: 'text/csv;utf-8'});
var url = URL.createObjectURL(file);
chrome.downloads.download({
    url: url,
    filename: name
}, function() {
    URL.revokeObjectURL(msg.url);
});
Sign up to request clarification or add additional context in comments.

Comments

-1

It worked for me (in a HTML test page at least) to use utf-16 charset instead. It worked both for the entity codes and the actual hebrew characters to be printed as hebrew characters.

So, change

{type: 'text/csv;utf-8'});

to

{type: 'text/csv;utf-16'});

1 Comment

Sorry, still the same.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.