问题
I am having trouble exporting some data from one meteor application (meteor application 1) as a CSV, then uploading that CSV file to a separate meteor application (meteor application 2) . Specifically, while the file is exported from meteor application 1 with utf-8 encoding, I do not know how to “tell” meteor application 2 that the csv encoded in utf-8 format. As a result, the data, as received by meteor application 2 gets corrupted with utf-8 jargon like “%u2019” etc
I’m using the package clinical:csv from atmosphere.js, which is built on top of Papa Parse.
The relevant exporting lines of code in meteor application 1 are:
'click #exportMe':function(){
var csvContent = CSV.unparse(Tasks.find().fetch());
window.open('data:text/csv;charset=utf-8,' + escape(csvContent), '_self');
},
The relevant importing lines of code in meteor application 2 are:
Template.example.events({
'change #hiddenUpload': function(event){
var filesList = event.currentTarget.files;
var file = filesList[0];
Papa.parse(file, {
header:true,
complete: function(results) {
var data = results.data
Meteor.call('tasks.batch',data)
}
});
},
})
I would guess that there would be a way of specifying in the importing code, that it’s encoded in utf-8, but have not been able to find anything in any relevant documentation.
Would be really grateful for any help.
回答1:
Use the encoding
option (alongside header
and complete
) of Papa.parse
http://papaparse.com/docs#config
As for the "%uxxxx" characters, they are not caused by the utf-8 charset encoding, but by the escape function that you apply.
回答2:
Try Using google sheets ,microsoft excel has a problem and also set UTF-8 encoding on papa parser.For me i changed from microsoft excel to google sheet and it worked.
回答3:
In your code, try putting a encoding option like below:
Papa.parse(file, { header:true, encoding: "ISO-8859-1", complete: function(results) { var data = results.data Meteor.call('tasks.batch',data) } });
来源:https://stackoverflow.com/questions/48574894/importing-utf-8-encoded-csv-in-meteor-using-papa-parse