2

I am using Super CSV for creating CSV file. When I write special characters like umlaut characters ï or î then it breaks in the generated CSV when I open it using Excel. When I open the same file using Notepad++ it shows the umlaut characters perfectly.

Any idea what could be the cause? I have specified UTF-8 encoding. Is there something that I am missing?

ICsvListWriter writer = new CsvListWriter(
    getWriter(getCUSTOMEREXPORT_FOLDERPATH()+filename),
    CsvPreference.STANDARD_PREFERENCE);

private static OutputStreamWriter getWriter(String fileName) {
  final File file = new File(fileName);
  return new OutputStreamWriter(new FileOutputStream(file),
      Charset.forName("UTF-8"));
}
Duncan Jones
  • 59,308
  • 24
  • 169
  • 227
  • possible duplicate of [Is it possible to force Excel recognize UTF-8 CSV files automatically?](http://stackoverflow.com/questions/6002256/is-it-possible-to-force-excel-recognize-utf-8-csv-files-automatically) – Duncan Jones Dec 10 '13 at 11:44
  • Answer does not really help. – Michael-O Dec 10 '13 at 11:47
  • Can you confirm that Notepad++ says the file is UTF-8 encoded? Also, I'm not sure which version of Excel you're using, but in 2010 you can try Data->From Text to import the CSV - it lets you select the encoding and shows you a preview. – James Bassett Dec 10 '13 at 23:37
  • Interestingly, as @Michael-O's suggested, I tried encoding a file with UTF-8 (without BOM) in np++ and opened the file in excel - it displayed the characters as ï and î. However it actually worked when I imported it instead. – James Bassett Dec 10 '13 at 23:44
  • @HoundDog, Say in NP++ that this is a UTF-8 file and everything is going to be fine. – Michael-O Dec 11 '13 at 07:11

1 Answers1

3

Microsoft and its Excel are too stupid for UTF-8. Excel strictly requires a byte order mark to realize that this is UTF-8 actually. Add it and it will work.

Michael-O
  • 17,130
  • 6
  • 51
  • 108