2

I am trying to export some data in csv format, it is fetched from my database (mongodb) with AJAX calls.

The problem is that special characters (e.g é à) are not displayed correctly in Excel after the CSV import.

However, they are correctly displayed on LibreOffice/Open Office, Google Spreadsheetm, and any text editor I could try.

I assume that the file is encoded in UTF-16 since it's generated from javascript.

Here's how I created the export in JavaScript (this is AngularJS) :

  $scope.downloadCityCSV = function() {
    $scope.csvURL = 'building';
    var data = 'email;first name;last name;Email confirmé;city;quantity;date\n';
    $scope.campaignData.cityVotes.forEach(function(vote) {
      var customer = vote.customer;
      data += customer.email +';' + customer.firstName +';' + customer.lastName +';' + (customer.accountConfirmed?"O":"N") +';' + vote.cityProposal + ';' + vote.quantity + ';' + vote.created + '\n';
    });
    var blob = new Blob([data], { type : 'text/csv' });
    $scope.csvURL = (window.URL || window.webkitURL).createObjectURL(blob);
  };

Did I do something wrong?

Vincent Taing
  • 3,283
  • 2
  • 18
  • 24

0 Answers0