473,385 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

characters with accent sor umlauts get written wrong

I am using the code snippet below. If the datagrid displays words with
french accent 'e' like 'cafe' or 'Toshiba Protege', the file test.xls
displays these e's as garbled 3 characters.

Do I need to do some formatting or specify some code page, langauge..etc?

StreamWriter sr;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new
HtmlTextWriter(sw);
myDataGrid.RenderControl(htw); sr =
File.CreateText("test.xls");
sr.WriteLine(sw.ToString());
John Dalbeg
Feb 15 '06 #1
1 1835
Thus wrote John,
I am using the code snippet below. If the datagrid displays words with
french accent 'e' like 'cafe' or 'Toshiba Protege', the file test.xls
displays these e's as garbled 3 characters.

Do I need to do some formatting or specify some code page,
langauge..etc?
File.CreateText() uses UTF-8 as character encoding. It seems Excel (I'm using
2003 SP2) doesn't correctly decode such a file if it is simply opened by
double clicking. But if you open the file from within Excel, you can choose
the correct encoding and process the file successfully.
StreamWriter sr;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new
HtmlTextWriter(sw);
myDataGrid.RenderControl(htw); sr =
File.CreateText("test.xls");
sr.WriteLine(sw.ToString());


As a workaround, simply create your text file with a Windows specific encoding
(Windows-125x), usually exposed as Encoding.Default.

sr = new StreamWriter("test.xls", false, Encoding.Default);

If you can't use the default settings for file access applied by StreamWriter
internally, create a FileStream with your specific accesss flags set first,
and pass that to your StreamReader:

sr = new Streamwriter(fileStream, Encoding.Default);

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Feb 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

114
by: muldoon | last post by:
Americans consider having a "British accent" a sign of sophistication and high intelligence. Many companies hire salespersons from Britain to represent their products,etc. Question: When the...
5
by: Matthew Shaw | last post by:
We have a web-based reporting application written in J2EE that writes out to excel using response.setContentType ("application/vnd.ms-excel; ")…. The problem is that where we have any special...
0
by: Markus Wollny | last post by:
Hi! Sorry to bother you, but I just don't know how to get tsearch2 configured correctly for my setup. I've got a 7.4.3 database-cluster initdb'ed with de_DE@euro as locale, the database is with...
2
by: Alan Searle | last post by:
For reporting purposes I generate XML from an MS-Access 2002 database and find that in this way I can format and display the data no problem with a XSL/HTML template. Perfect! However, then I...
0
by: Fabrice | last post by:
Hello, (Alain) Tis is a part of my code to retrieve text from hastable in memory cache, by reading (befor) a resources file. Thanks for your help. /1/ The resources file * I have create a...
8
by: santiago | last post by:
Editing XML with special characters like ç á ñ Hello. I have to code a multilanguage website. As it will be very static, I set things up so everything is loaded from an XML file. However, as...
1
by: Roberto Rocco | last post by:
Hello, I'm using VS 2005 and I need to send a mail body which contains german umlauts (ä,ö,ü). When I receive the mail in Outlook 2003 (english operating system) I always get a '|' or other...
10
by: Mike Schilling | last post by:
I've created a simple .NET 1.1 web service using VS.NET 2003: it has one method that takes a string parameter. It iterates through the input string, turning each character into hex and appending...
13
by: TK | last post by:
Hi, how can I handle multibyte characters like ä, ü (german vowel mutation)? This does't work: switch(c) case 'ä': ... some action
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.