Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting the BOM on write #180

Closed
bizarrochris opened this issue Mar 29, 2017 · 5 comments
Closed

Setting the BOM on write #180

bizarrochris opened this issue Mar 29, 2017 · 5 comments

Comments

@bizarrochris
Copy link

bizarrochris commented Mar 29, 2017

Hi, we use the npm module to create csv exports and are generally very happy, however we still have the issue with utf-8 encoding, that excel does not recognise the files as utf-8 immediately.

According to: http://stackoverflow.com/questions/155097/microsoft-excel-mangles-diacritics-in-csv-files
adding the BOM would be the quickest fix.
Is there a way to add this to the stream. Our code looks like this (we use express.js):

const csvOptions = {
            headers: true,
            delimiter: ';',
            transform: function(entry) {
//do stuff
            }
          };
          response.set('Content-Type', 'text/csv; charset=utf-8');
          response.set('Content-Disposition', 'attachment; filename="export.csv"');
          csv.write(transactions, csvOptions).pipe(response);

If there is no way to do it, an option would be amazing to set the BOM.
Thx in advance.

@dustinsmith1024
Copy link
Contributor

I am not quite sure how to do this. Maybe you can do it like adaltas/node-csv#84 (comment)?

You might have to make an extra stream and pipe one through the other though. Maybe someone else can provide a better example.

@dustinsmith1024
Copy link
Contributor

Or see: keystonejs/keystone#748 (comment)

@bizarrochris
Copy link
Author

bizarrochris commented Mar 29, 2017

Thank you for the options - will check them out asap.
However, having a BOM in the options, and adding the BOM to the document in the background) would still make a lot of sense inmho.

@harryluo91
Copy link

Hi @bizarrochris did you find a way to work around this? We are also having the same issue but couldn't get it working with a stream.

doug-martin added a commit that referenced this issue Jul 30, 2019
* [ADDED] `writeBOM` option when formatting a csv #180
@doug-martin doug-martin mentioned this issue Jul 30, 2019
7 tasks
doug-martin added a commit that referenced this issue Jul 30, 2019
* [ADDED] `writeBOM` option when formatting a csv #180
doug-martin added a commit that referenced this issue Jul 30, 2019
* [ADDED] `writeBOM` option when formatting a csv #180
doug-martin added a commit that referenced this issue Jul 30, 2019
@doug-martin
Copy link
Contributor

Added in v3.4.0 there is a new option called writeBOM that you can set to true to have the BOM character written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants