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

add support for bom #63

Open
MonksterFX opened this issue Feb 24, 2021 · 1 comment
Open

add support for bom #63

MonksterFX opened this issue Feb 24, 2021 · 1 comment

Comments

@MonksterFX
Copy link

For special characters like ÄÖÜ in german language it requires to set a BOM in utf-8 export to have a correct import in programs like MS Excel.

Is it possible to add an parameter to add an bom. Work arround is:

csvWriter.writeRecords(dataExportCsv).then(() => {
    fs.writeFileSync('export.csv', '\ufeff' + fs.readFileSync('export.csv'));
  });
@brakmic
Copy link

brakmic commented Jul 16, 2024

Hi @MonksterFX ,

It seems the original project is abandoned, so I decided to fork it.

In my fork, I've added a useBom parameter to address this issue. I'm also working on solving other issues and incorporating unmerged PRs from the original project.

You can check out the forked project here:

Here's an example of how to use the useBom parameter:

import { createObjectCsvWriter } from 'csv-writer-portable';

const csvWriter = createObjectCsvWriter({
    path: 'test.csv',
    header: [
        { id: 'name', title: 'NAME' },
        { id: 'lang', title: 'LANGUAGE' }
    ],
    useBom: true,
});

const data = [
    { name: 'Müller', lang: 'German, French, English' },
    { name: 'Groß', lang: 'German, English' }
];

async function writeCsv() {
    await csvWriter.writeRecords(data);
}

writeCsv().catch(err => console.error('Error writing CSV:', err));

Feel free to try it out and let me know if you run into any issues.

Best,
Harris

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

No branches or pull requests

2 participants