Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oren - 23 Jan 2008 13:57 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.