Solved

writing excel file does not german chars in file when creating from asp.net

Posted on 2009-05-14
5
338 Views
Last Modified: 2012-05-07
I am creating multiple excel files from html table object.
this html table does some German chars along with the English text.
when i running the code the excel file is getting created but the German chars get replaced by junk chars.
I tried to changed the Encoding to UTF 7 but then the whole excel contains only junk chars.

can any one help me out here how can  export multi language data from html table to excel sheet.
here is the code
 
            StringWriter dd= new StringWriter();
 
 
 
 
            HtmlTextWriter htw = new HtmlTextWriter(dd);
 
            table.RenderControl(htw);
 
            counter += 1;
            fullFileName = "ExportDB" + counter.ToString() + ".xls";
            string filePathName = HttpContext.Current.Server.MapPath("ExcelFile/" + fullFileName);
 
            if (File.Exists(filePathName)) { File.Delete(filePathName); }
            FileStream Fs = new FileStream(filePathName, FileMode.Create);
            BinaryWriter BWriter = new BinaryWriter(Fs, Encoding.UTF7);
 
            BWriter.Write(dd.ToString());
            BWriter.Close();
            Fs.Close();

Open in new window

0
Comment
Question by:ziorrinfotech
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24385986
the reason is most probably because the web page that is posting the characters to the writer is not pushing using the right character set...

put this in your page:

<meta http-equiv="Content-Type" content="text/html; charset=CharacterSet">

replace characterset with the proper one for your situation.
0
 

Author Comment

by:ziorrinfotech
ID: 24388316
I added  <meta http-equiv="Content-Type" content="text/html; charset=UTF-7"> in the head tag but still it does not work.

i am attaching a screen shot of output which iam getting
a.JPG
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24432706
Ok, this to me looks like you're using Server.URLEncode on your text before you send it to the Excel file, Correct?
0
 

Author Comment

by:ziorrinfotech
ID: 24433656
yes that is correct i am Server.URLEncode
0
 
LVL 10

Accepted Solution

by:
MaxOvrdrv2 earned 125 total points
ID: 24433694
that is the reason why your characters show up as they are... if you want the characters to show up in the excel file properly, you must remove the server.URLEncode, or if you need the server.URLEncode to pass it to a different page before sending it, then you must use the Server.URLDecode() before/during the save to the excel file.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question