react-csv
react-csv copied to clipboard
Values with double quotes and commas spitting into multiple cells in exported csv
how to solve
How to solve this issue? anyone has any update?
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
Has anybody solved this issue somehow? I am running into the same
Replacing all existing double quotes into 2 double quotes fixed my problem.
str.replace(/"/g, '""');
Regarding commas inside the text I resolved it by adding
enclosingCharacter={`"`}
to the components props.
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.
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.
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.
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
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 ''
}
I solved it by changing my lib version to 2.1.9
and using props enclosingCharacter with empty string value, like:
enclosingCharacter=""
Replacing all existing double quotes into 2 double quotes fixed my problem.
str.replace(/"/g, '""');
Thx sooo much to solve this problem!
I solved it by changing my lib version to
2.1.9
and using props enclosingCharacter with empty string value, like:
enclosingCharacter=""
Thanks!