Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right CSV encoding for c# to open with Excel?

I write a CSV with my C# CSVWriter based on a StreamWriter. In my data I have a lot of special characters like "Bávaro".

So when I use UTF-8 or ASCII to encode my CSV I can't get the "á" but I can open it in Excel afterwards perfectly. When I use Unicode my CSV has the correct char but in fact when I open this CSV in Excel it doesnt get automaticly sorted like my other CSV, all values are in the first column as string....

What is the right encoding here?

like image 919
PassionateDeveloper Avatar asked Oct 19 '22 11:10

PassionateDeveloper


1 Answers

I recommend using Windows ANSI Codepage 1252 which you can get via:

Encoding.GetEncoding(1252)

It supports characters like "á" and works well from Excel 2003 to Excel 2013.

like image 72
Paul Weiland Avatar answered Oct 22 '22 03:10

Paul Weiland