asafdav / ng-csv

Simple directive that turns arrays and objects into downloadable CSV files
MIT License
573 stars 215 forks source link

Using add-bom broken? #73

Closed Icydillic closed 9 years ago

Icydillic commented 9 years ago

Hi, I tried using the add-bom option when creating a new .csv file. The element properties look like this:

  ng-csv="dataPromise()" csv-header="header()" lazy-load="true"
  filename="test.csv" field-separator=";" add-bom="true"

When exporting the file with the "add-bom"-Option it only writes me the stringified hex-value "%ef%bb%bf" into the file. Normaly this shouldn't be the string value I guess. I saw that there are bom-issues and they were resolved, so I don't know what I am doing wrong here. Am I missing something?

Kind regards, Stefan

PS: I see you changed from data uri to blob. Perhaps this is the issue?

asafdav commented 9 years ago

Hi, it seems like it is broken (see it here: https://asafdav.github.io/ng-csv/example/)

I'll take a look

Icydillic commented 9 years ago

I found the reason: Have look into the service line 206 you are missing the decodeURIComponent() function to decode '%ef%bb%bf' or you could use '\ufeff' instead.

Kind regards, Stefan

PS: As a workaround in the meanwhile you could simply add \uFEFF to the first header column.

asafdav commented 9 years ago

Can you pull request? I'll take a look

On Mon, Dec 15, 2014 at 4:46 PM, Stefan notifications@github.com wrote:

I found the reason: Have look into the service line 206 you are missing the decodeURIComponent() function to decode '%ef%bb%bf' or you could use '\ufeff' instead.

Kind regards, Stefan

PS: As a workaround in the meanwhile you could simply add \uFEFF to the first header column.

— Reply to this email directly or view it on GitHub https://github.com/asafdav/ng-csv/issues/73#issuecomment-67003592.

Icydillic commented 9 years ago

I'm affraid I don't know how. The error is in the build section in the ng-csv.js and I don't know how it is created. :o( History: https://github.com/asafdav/ng-csv/commit/05ecc183d915d3ac65f0fa8253523bca0f79fa39 These changes:

if(window.navigator.msSaveOrOpenBlob) {
-            var blob = new Blob([decodeURIComponent(scope.csv)],{
-                    type: "text/csv;charset=utf-8;"
-                });
+          var blob = new Blob([scope.csv], {
+            type: "text/csv;charset=utf-8;"
+          });
Icydillic commented 9 years ago

I created a pull request in the build/ng-csv.js.

asafdav commented 9 years ago

Fixed by #75