0

I am manually writing .csv files using Python/Django and then attempting to open those .csv files using Excel for Mac version 15.21.1.

enter image description here

I can successfully escape all of the , characters, but am unable to escape " characters.

For example...
I have a bit of data...

hell"oworld

How do I escape the " from that data? I have tried (per advice of others on SO) to use solutions such as doubling the quote like so hell""oworld and have also tried something like hell" & CHAR(34) & oworld to no avail. I understand that character escaping is tricky business, but could someone please throw me a bone?

Already tried these suggestions...
solution1

Community
  • 1
  • 1
Erik Åsland
  • 9,542
  • 10
  • 30
  • 58
  • Have you tried \" ? Sorry I don't know Python but that is used in bash maybe the same? – Kent May 17 '16 at 21:49
  • 3
    Don't do it manually: Use python's `csv` module. Quoting is pretty much its whole raison d'etre. – alexis May 17 '16 at 21:49
  • @alexis I don't have a choice in the matter. What the boss says is what the boss says. – Erik Åsland May 17 '16 at 21:50
  • Bummer. Then spend 15 minutes writing out a file with `csv`, see how it does it and imitate it. ;-) The `csv` module defines several "dialects", and you may have to experiment until you get something that does indeed get read in. (My Excel didn't recognize the "Excel" dialect on the first try-- a line ending problem, if I remember correctly.) – alexis May 17 '16 at 21:55
  • Have you tried the advice in [this question](http://stackoverflow.com/questions/12473480/how-should-i-escape-commas-and-speech-marks-in-csv-files-so-they-work-in-excel?rq=1), by the way? Yours looks like a duplicate of it. If it didn't work, add the info to your question. – alexis May 17 '16 at 22:00
  • @alexis Yes. That was the first one I went to and tried. – Erik Åsland May 17 '16 at 22:04
  • Editing your question to specifically say so will protect it from being closed as a duplicate... – alexis May 17 '16 at 22:08
  • It would be interesting, as an aside, to understand why your boss (or anyone) would object to the use of python's built-in csv package. It's like objecting to the use of dict, or integers... – Tom Dalton May 17 '16 at 23:31
  • @TomDalton It would be very interesting to actually understand his thought process, but he is a jerk and I really don't want to lose my job. – Erik Åsland May 17 '16 at 23:35
  • Ha ha, fair enough. I'm sorry to hear that :-( – Tom Dalton May 18 '16 at 06:59

1 Answers1

0

there is a lot of answers, e.g this or this one

when you escape text - it should be enclosed by quotation marks, then if you have a quotation mark in the text itself, it should be replaced by two quotation marks:

do if you have hell"oworld as your cell value, in the .csv file you shoud have:

"hell""oworld"

Community
  • 1
  • 1
Jerzyk
  • 3,662
  • 23
  • 40