Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 635
sid_com Avatar asked Jan 26 '10 12:01

sid_com


People also ask

What characters need to be escaped CSV?

By default, the escape character is a " (double quote) for CSV-formatted files. If you want to use a different escape character, use the ESCAPE clause of COPY , CREATE EXTERNAL TABLE or gpload to declare a different escape character.

How do I show a double quote in a csv file?

Double-quote escape characters There are 2 accepted ways of escaping double-quotes in a CSV file. One is using a 2 consecutive double-quotes to denote 1 literal double-quote in the data. The alternative is using a backslash and a single double-quote.


1 Answers

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).

like image 175
Buttle Butkus Avatar answered Oct 11 '22 09:10

Buttle Butkus