Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks everyone for the help, I finally managed to get a working - double clickable csv file which opens separated and displaying the letter correctly. For those who are interested in a good workflow here we go:</p> <p>1.) My database is completely using UTF8. 2.) I export a form into my database via php. I'm using mysqli and as header information:</p> <pre><code>header("Content-Type: text/html; charset=ISO-8859"); </code></pre> <p>I know this makes everything look crappy inside the database, feel free to use utf8 to make it look correctly but it doesn't matter in my case.</p> <p>3.) I wrote a script executed by a cron daemon which a) removes the .csv files which were created previously</p> <pre><code>rm -f path/to/csv ##I have 3 due to some renaming see below </code></pre> <p>b) creating the new csv using mysql (this is still UTF8)</p> <pre><code>mysql -hSERVERIP -uUSER -pPASS DBNAME -e "select * from DBTABLE;" &gt; PATH/TO/output.csv </code></pre> <p>Now you have a tab separated .csv and (if u exported from PHP in UTF8) it will display correctly in OpenOffice etc. but not in Excel. Even an import as UTF8 isn't working.</p> <p>c) Making the file SEMICOLON separated (Excel standard, double clicking a comma separated file won't work at least not with the european version of Excel). I used a small python script semicolon.py:</p> <pre><code>import sys import csv tabin = csv.reader(sys.stdin, dialect=csv.excel_tab) commaout = csv.writer(sys.stdout, delimiter=";") for row in tabin: commaout.writerow(row) </code></pre> <p>d) Now I had to call the script inside my cron sh file:</p> <pre><code>/usr/bin/python PATH/TO/semicolon.py &lt; output.csv &gt; output_semi.csv </code></pre> <p>Make sure you use the full path for every file if u use the script as cron.</p> <p>e) Change the charset from UTF8 to ISO-8859-1 (Windows ANSI Excel standard) with iconv:</p> <pre><code>iconv -f utf8 -t ISO-8859-1 output_semi.csv &gt; output_final.csv </code></pre> <p>And that's it. csv opens up on double click on Mac/Windows Excel 2010 (tested).</p> <p>Maybe this is a help for someone with similar problems. It drove me crazy.</p> <p>Edit: For some servers you don't need iconv because the output from the database is already ISO8859. You should check your csv after executing the mysql command:</p> <pre><code>file output.csv </code></pre> <p>Use iconv only if the charset isn't iso8859-1 </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload