Im using excel as a DB in asp.net .
I get a request with parameteres in hebrew.
I read them and then write them to excel file.
English and numbers looks fine in the excel file but the hebrew is
gibbrish.
So its something like:
string sName = Request.Form["Name"];
FileInfo f = new FileInfo(XLS_FILE_PATH);
StreamWriter w = f.AppendText();
w.WriteLine(sName );
w.Close();
Any ideas ?
Thanks.
Jon Skeet [C# MVP] - 23 Jan 2008 14:16 GMT
> Im using excel as a DB in asp.net .
> I get a request with parameteres in hebrew.
[quoted text clipped - 7 lines]
> w.WriteLine(sName );
> w.Close();
You need to check at least two things:
1) Is sName correct in memory?
2) Is the file correct if you look at it in a hex editor?
If you can tell Excel to open a file in a particular encoding, try
UTF-8.
Jon
Anthony Jones - 23 Jan 2008 15:11 GMT
> Im using excel as a DB in asp.net .
> I get a request with parameteres in hebrew.
[quoted text clipped - 7 lines]
> w.WriteLine(sName );
> w.Close();
You should make sure the source page specifies UTF-8 as its encoding (so
that form data is actually posted up using UTF-8).
Try adding the line
Response.Write(w.Encoding.EncodingName);
Discover what encoding the file is in. I suspect it will be in a OEM
codepage not UTF-8.

Signature
Anthony Jones - MVP ASP/ASP.NET
Jon Skeet [C# MVP] - 23 Jan 2008 15:18 GMT
<snip>
> Discover what encoding the file is in. I suspect it will be in a OEM
> codepage not UTF-8.
Well the file written out by the StreamWriter will definitely be in
UTF-8, because that's the default encoding for a StreamWriter. It
doesn't mean that Excel is expecting that though!
Jon
Anthony Jones - 23 Jan 2008 22:38 GMT
> <snip>
>
[quoted text clipped - 4 lines]
> UTF-8, because that's the default encoding for a StreamWriter. It
> doesn't mean that Excel is expecting that though!
So it does. Even if there isn't a BOM. Which means you need to know before
hand the encoding used to write the file originally.
Excel doesn't cope with UTF-8 even with a BOM present. (At least not as of
2003 perhaps later versions can). I'm assuming we're talking .csv.

Signature
Anthony Jones - MVP ASP/ASP.NET