Answer the question
In order to leave comments, you need to log in
Why is the wrong encoding saved in csv format?
The question is the following, there is a collection of Clients and you need to backup it to a csv file. After subscribing and clicking, you should:
$scope.saveAll = function(){
function JSON2CSV(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
var line = '';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
var value = array[i][index] + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
line = line.slice(0, -1);
str += line + '\r\n';
}
return str;
}
var jsonObject = JSON.stringify($scope.clients);
var csv = JSON2CSV(jsonObject);
window.open(encodeURI('data:text/csv;charset=utf-8,' + csv));
console.log(csv);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question