5

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?

2
  • Excel can open CSV encoded in UTF-8 only with the correct encoding if the CSV file contains a BOM at its beginning. Unicode (UTF-16) encoded CSV will only be opened correctly if they are tabulator delimited and not comma (or semicolon) delimited. Commented May 22, 2015 at 6:55
  • Try to add preamble bytes to file, as I wrote here: stackoverflow.com/a/46076517/908936 Commented Sep 6, 2017 at 13:30

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Export your CSV using this encoding Encoding.GetEncoding("Windows-1252")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.