Exporte JSON para CSV ou Excel com codificação UTF-8 (por exemplo, grego) usando JavaScript

Estou tentando exportar e baixar umJSON opor-se aCSV arquivo e tenho problemas com caracteres gregos. Meu código funciona; não é perfeito, mas funciona.

O problema é que os caracteres gregos parecem lixo.

Aqui está o meu código existente:

function downloadJsonToCsv(jsonObject) {
    var array = typeof jsonObject != "object" ? JSON.parse(jsonObject) : jsonObject;

    if (array == null) {
        return; // No data found on the jsonObject
    }

    var str = "";

    for (var i = 0; i < array.length; i++) {
        var line = "";

        for (var index in array[i]) {
            line += array[i][index] + ";"; // Set delimiter
        }

        // Here is an example where you would wrap the values in double quotes
        // for (var index in array[i]) {
        //    line += '"' + array[i][index] + '",';
        // }

        line.slice(0,line.Length-1); 

        str += line + "\r\n";
    }

    window.open("data:text/csv;charset=utf-8," + encodeURI(str));
}

Eu tenho duas perguntas.

Como exportar issoCSV arquivo com caracteres gregos corretos?Como posso exportar esses dados emExcel formato e não emCSV formato?

questionAnswers(2)

yourAnswerToTheQuestion