node-csv icon indicating copy to clipboard operation
node-csv copied to clipboard

How to generate emoji content correctly?

Open jiahao-si opened this issue 3 years ago • 4 comments

I need to transfer emoji into csv, but it doesn't work ,and I have already set the bom of UTF-8.

image

The result is : image

jiahao-si avatar Aug 22 '22 07:08 jiahao-si

Hi @jiahao-si, this is not related to the parser. Your emoji is made of bytes just like any other information. The parser doesn't modify it and return it, just in a different format. If you want more help, share with us some sample code of your input, your desired output, and without any image or screenshot.

wdavidw avatar Aug 22 '22 08:08 wdavidw

Hi @wdavidw , I just wrote a demo, and the result is what the screenshot show.

` // Import the package main module import * as csv from 'csv' import { createWriteStream } from 'fs';

// Generate 20 records const generator = csv.generate({ delimiter: '|', length: 20 }) // Transform CSV data into records const parser = csv.parse({ delimiter: '|' }) // Transform each value into uppercase const transformer = csv.transform((record) => { return record.map((value) => { return value.toUpperCase() }); }) // Convert objects into a stream const stringifier= csv.stringify({ cast: { string: (value, context) => { // to test emoji return context.index % 2 ? '🤔' : value.toUpperCase(); } }, quoted: true, // add bom_utf8 bom: true })

const writeCsv = createWriteStream('1.csv');

// Run the pipeline generator .pipe(parser) .pipe(transformer) .pipe(stringifier) .pipe(writeCsv)

`

image

jiahao-si avatar Aug 22 '22 09:08 jiahao-si

By the way , I opened the csv file using Excel

jiahao-si avatar Aug 22 '22 10:08 jiahao-si

Please, if you want any help:

  • a much more simplified example with only the minimal necessary code with input -> parse or (not and) stringifiy > expected output
  • no screenshot
  • no excel, this library is not doing anything directly with Excel, I don't even have it. If you want to know how emoji are rendered within excel, create a file, open it in Excel and see if it work.

wdavidw avatar Aug 22 '22 10:08 wdavidw

Closing for lack of activity

wdavidw avatar Aug 25 '23 12:08 wdavidw