I tried Unicode and Windows-1252, witch are not in the given list of tried encoding, but no matter, Excel 2007 don't recognise such letters as "é". Witch encoding should I use with a swiss-french or european system?
Main Topics
Browse All TopicsI tried a list of encoding my CSV files to export, but Microsoft Excel 2007 didn't want to recognise it. Her is the list:
- Response.ContentEncoding = System.Text.Encoding.GetEn
- Response.ContentEncoding = System.Text.Encoding.GetEn
- Response.ContentEncoding = System.Text.Encoding.GetEn
- Response.ContentEncoding = System.Text.Encoding.Defau
- Response.ContentEncoding = System.Text.Encoding.UTF8;
- Response.ContentEncoding = System.Text.Encoding.UTF7;
- Response.ContentEncoding = System.Text.Encoding.Defau
- Response.ContentEncoding = System.Text.Encoding.BigEn
- Response.ContentEncoding = System.Text.Encoding.ASCII
- Response.ContentEncoding = System.Text.Encoding.UTF32
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If you don't specify an encoding at all, the default should be used (this is different then Encoding.Default). For French, the normal encoding on Windows systems is Windows-1252. Other encodings that are well-suited and often used for French are ISO-8859-1 and ISO-8859-15 (with euro and Y+diaeresis).
If your é does not look good in Excel, how does it look? Can you give a small cut-out screenshot? You can also try it the other way around: save a file as CSV with these characters in it and then read it back in, does that work? If it does, can you post the file as attachment here, then I can tell you what encoding to use.
-- Abel --
Looking again at your code, I think that something else maybe the problem. You are not exporting as CSV at all. Instead, you are using a trick, you give the name and headers for excel and then you output html. Try the same trick with the proper headers, and especially, include the following, which must match your encoding (use UTF8 for best coverage):
I tried ISO-8859-15 encoding, but always the same problem. The CSV file directly created works (test.csv in attachement). I send you also a screenshot of a UTF-8 CSV document.
The code export in Excel 2003 HTML format. This part of the code is working well. But it also tries to export in CSV for Excel 2007 (see GiveCSSResponse).
I'm not surprised that other encodings do not work. That follows from your earlier reports.
The screenshot is clear: Excel reads it in as if it is ISO-8859-1 (or windows-1252) and that changes the letters into double letters for UTF8. What surprises me is that when you use the windows-1252 encoding, that it doesn't work.
What misses in your code is the CharSet, this should be "utf-8" (or another corresponding charset).
What also misses is what I said in my last comment: try adding correct HTML headers for the output, which may help the guessing game of Excel, which is currently apparently off.
Finally, check whether the HeaderEncoding and the ContentEncoding match and are the same.
-- Abel --
> I tried to use ISO-8859-1 and windows-1252 with a CharSet of "utf-8",
nono, I meant, quote: "or another corresponding charset", be exactly equal. So, windows-1252 with a charset of windows-1252. That must be followed by an HTML header with the same charset.
> Normaly, I should read the "é" char
I know. What you are creating is a UTF-8 file and what Excel is reading is a windows-1252 file. The file you have send here is that same file, saved again as CSV, hence that the encoding contains even more oddities.
The encoding must be the same on all ends for this to work. As long as that is not the case, it will not work.
I am under the impression that you first save the file to disk and then you open it in Excel. Is that correct?
From reports it seems that you need to add the BOM. It is a bug of Microsoft. Unfortunately, the current method for creating the CSV does not allow to add the BOM manually. http://www.jaanuskase.com/
Ah, something else I noticed with your code, all of a sudden, you are apparently not clearing the headers. It didn't occur to me earlier. But just Clear does not clear the headers. Use ClearHeaders for that. Don't think this will help, but you can try.
When you view your data without the content-disposition inside a browser, how does it look, is the é showing up correctly?
Ok, if somehow we cannot manage to get all encodings equal, or if we are somehow blocked by Microsoft Excel bugs, one must try other approaches. Try the following (I cannot try it, but I tested it nonetheless):
1. Use Clear and ClearHeaders
2. Set all places where you have an encoding or a charset etc to utf-8
3. As very first statement, use the line in the code section
4. Do what you normally do
This will force a BOM (byte order mark). This is not necessary, but Microsoft Office products are famous to ignore UTF8 when it clearly is, and starting out with this unique three bytes (EF BB BF) hopefully forces the encoding on Excel. See also the link above which brought me to this idea.
PS: you are writing HTML, which is not CSV which can be the reason for your failure, too. Instead, use the normal Excel extension and mime type "application/vnd.ms-excel"
Business Accounts
Answer for Membership
by: abelPosted on 2009-08-31 at 09:01:00ID: 25223879
The default is the default for the current system. For US based systems, that is Windows-1252. However, Excel shouldn't have trouble with UTF8 or UTF16 (Encoding.Unicode) either (but UTF7 or UTF32 are really out, don't use them).