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

Values with double quotes and commas spitting into multiple cells in exported csv

Open ghost opened this issue 3 years ago • 14 comments

ghost avatar Oct 08 '20 17:10 ghost

how to solve

hyypan avatar Oct 16 '20 07:10 hyypan

How to solve this issue? anyone has any update?

ghost avatar Oct 16 '20 14:10 ghost

Hi All , I am also using this library for our project but having issue with double quote , so as an requirement we want double in our field but when we export CSV then all columns after that fields get messed up . so we want double quote in cell along with other fields should exported normally does this issue still on or resolved ??

having same issue but still no resolution

nandkishorb avatar Nov 06 '20 08:11 nandkishorb

Has anybody solved this issue somehow? I am running into the same

miguelc95 avatar Nov 12 '20 18:11 miguelc95

Replacing all existing double quotes into 2 double quotes fixed my problem. str.replace(/"/g, '""');

iKlaire avatar Jan 20 '21 03:01 iKlaire

Regarding commas inside the text I resolved it by adding

enclosingCharacter={`"`}

to the components props.

ThanosDi avatar Feb 12 '21 12:02 ThanosDi

Replacing all existing double quotes into 2 double quotes fixed my problem. `str.replace(/"/g, '""');

Same problem here. The @iKlaire hack works for me, but it still a hack.

serenaPattaroCardT avatar Mar 29 '21 15:03 serenaPattaroCardT

Fwiw I had to change to the "array literal object" format described in the docs instead of a string to get this to work. Seems to work fine if you feed a JS object that has strings that contain commas, just not if you feed in a csv-formatted string that contains quoted cells with commas.

willow-p avatar Apr 05 '22 14:04 willow-p

Unless I am mistaken the code does no encoding internally, to handle embedded quotes. For a library I would say this is a must. The challenge is now I am doing the string replacement which means any future update to fix this will be a breaking change.

ocdi avatar Apr 08 '22 08:04 ocdi

Same issue. I was able to solve it by downgrading to 2.1.9. This the release before https://github.com/react-csv/react-csv/commit/7d00a46ff2da2e9c7eacdeaac20440f08c9b2a65

jesgueva avatar May 19 '22 16:05 jesgueva

Downgrading to 2.1.9 worked for me.

Use this in the props

enclosingCharacter={`"`}

Surround cells with string values inside quotes. This escapes commas inside cells.

const value = obj[key]
if (typeof value === 'string') {
    return `"${value}"`
} else if (typeof value === 'number') {
    return value
} else {
    return ''
}

SamWhillance avatar Oct 25 '22 22:10 SamWhillance

I solved it by changing my lib version to 2.1.9 and using props enclosingCharacter with empty string value, like:

enclosingCharacter=""

Cleysond10 avatar Sep 06 '23 15:09 Cleysond10

Replacing all existing double quotes into 2 double quotes fixed my problem. str.replace(/"/g, '""');

Thx sooo much to solve this problem!

Sheepeer avatar Sep 07 '23 08:09 Sheepeer

I solved it by changing my lib version to 2.1.9 and using props enclosingCharacter with empty string value, like:

enclosingCharacter=""

Thanks!

fabioxd20 avatar Jan 10 '24 03:01 fabioxd20