asp.net C# writing hebrew to excel that uses asDB

  • Thread starter Thread starter Oren
  • Start date Start date
O

Oren

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.
 
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();

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
 
Oren said:
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();


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.
 
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
 
Jon Skeet said:
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!


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.
 
Back
Top