Openoffice - CSV-export: is there a default escape-charcter?

sid_com picture sid_com · Jan 26, 2010 · Viewed 7.1k times · Source

As far as I can see OpenOffice, when it comes to save a file as a csv-file, encloses all strings in quote-characters.

So is there any need for an escape character?

and related to this question:

Does OpenOffice have a default escape character?

Answer

Buttle Butkus picture Buttle Butkus · Jun 9, 2011

I'm also wondering if there is a way to choose the escape character when saving OpenOffice as csv. phpmyadmin was not accepting a 9,000 line 50+ column spreadsheed in .ods format and there doesn't seem to be a way to choose the escape character when saving as CSV.

So I had to save as csv, open in word, and use some find/replace tricks to change the escape character to \ (back slash). Default is to use double quotes to escape double quotes, and phpmyadmin won't accept that format.

To properly convert the file to use \ (back-slash) to escape double-quotes, you have to do this:

  1. Pick a placeholder character string, e.g. 'abcdefg', that does not occur anywhere in the csv.
  2. Find/replace """ (three double-quotes in a row) with the placeholder. This is to prevent possibly incorrect results in the next step.
  3. Find/replace "" (two quotes in a row, representing one quote that should be escaped), with \" (back-slash double-quote). If you did this without find/replacing """ it's conceivable you could get a result like "\" instead of \"". Better safe than sorry.
  4. Find/replace the placeholder string with \"" (back-slash double-quote double-quote).

That will work, unless you happen to have more than one double-quote in a row in your original text fields, which would result in as many as five double-quotes in a row in the resulting .ods or .xlsx csv file (two double-quotes for each escaped double quote, plus another double quote if its at the end of the field).