Solved

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

Posted on 2009-05-14
5
331 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now