Solved

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

Posted on 2009-05-14
5
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

615 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