CSV encoding specification

Go To StackoverFlow.com

0

I am creating a CSV and writing content in UTF-8 to support German and English by specifying encoding as below

BufferedWriter outFile = new BufferedWriter( new OutputStreamWriter( outputStream, "UTF-8" ) );

The above is working fine till I add the below separator indication (;) in the header of CSV

outFile.write( "sep=;" );
outFile.newLine();    

Without this delimiter ; my CSV will be wrong but when I inclde this the encoding is failing and UTf-8 not in place.

Is there any other keyword like "sep=" to specify in header of CSV to specify encoding?

I tried encoding="UTF-8" and it is not working.

Thanks.

2012-04-04 06:20
by Appasamy T
what language is this? and why isn't it in the tags - hroptatyr 2012-04-04 06:22
Hi, this is in Java. I added tags. Thanks for the indicatio - Appasamy T 2012-04-04 06:24
what do you mean by: encoding is failing - oers 2012-04-04 07:01
German characters are not showing properly. If the UTf-8 is set and Sep= not used then they are displaying properly. Thanks oer - Appasamy T 2012-04-04 07:08
Not showing? Which application are you using to display the CSV - Arnout Engelen 2012-04-04 08:05
Arnout, I am using Microsoft Excel 200 - Appasamy T 2012-04-04 08:13
What do you see with a normal text-editor like notepad++? And sep=; ist not really CSV, it seems to be an excel specific hack. You could also try to run java with -Dencoding=UTF8, or set the console encoding to UTF8 in your editor of choice - oers 2012-04-04 12:37
and my excel2007 opens csv-files without the sep=; just fine - oers 2012-04-04 12:39


0

You cannot open a UTF8 csv file with Excel 2007. Microsft have no understanding of the word "standards". Because of this, it is notoriously difficult to generate a csv file which opens in every possible application that reads .csv files and keeps the correct encoding.

If you must use Excel 2007, I would suggest using encoding with Microsofts own "windows 1252" as it supports German characters. Don't use the header, and also look in to using tab as a separator. Yes I know the c stands for comma, but tab seems to be more consistent with Excel 2007 if you save the file back again.

2017-06-07 23:20
by Phil
Ads