Solved

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

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

Independent Software Vendors: 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

734 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