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
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();
[quoted text clipped - 3 lines]
> 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,

Signature
Joerg Jooss
news-reply@joergjooss.de