Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-14
5
Medium Priority
?
350 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 375 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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 …
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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