Re: Chinese characters don't display on excel using asp.net

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Joerg Jooss (news-reply_at_joergjooss.de)
Date: 02/19/05


Date: Sat, 19 Feb 2005 02:22:04 -0800

c.verma@gmail.com wrote:

> I have a web application. There is a page which has a datagrid on
> it.The datagrid displays the data that comes from SAP. SAP sends the
> chinese characters to this grid. Before I display CHinese charactes, I
> have to use the following code to let it display on the web page:
>
> Public Function ToSCUnicode(ByVal str As String) As String
> Dim enc1252 As System.Text.Encoding =
> System.Text.Encoding.GetEncoding(1252)
> Dim arrByte_GBK As Byte()
> Dim arrByte_UTF16 As Byte()
> Dim encGBK As System.Text.Encoding =
> System.Text.Encoding.GetEncoding(936)
> Dim encUTF16 As System.Text.Encoding =
> System.Text.Encoding.Unicode
> Dim strUTF16 As String
>
> arrByte_GBK = enc1252.GetBytes(str)
>
> arrByte_UTF16 = System.Text.Encoding.Convert(encGBK, encUTF16,
> arrByte_GBK)
> strUTF16 = encUTF16.GetString(arrByte_UTF16)
>
> Return strUTF16
> End Function
>
> The web page has ALWAYS displayed the correct Chinese.
>
> The SAME web page I display in excel using the below code:
>
>
> If Request.QueryString("contenttype") = "excel" Then
> Response.Clear()
> Response.ContentType = "application/vnd.ms-excel"
> Me.EnableViewState = False
> Response.Charset = ""
>
> End If
>
> Problem: Few records display Chinese characters fine in excel but few
> display junk..
> I have tired setting up the regional settings to Chinese. Nothing was
> of any help.
>
> Any ideas?

You're code is really weird.

What is the purpose of ToSCUnicode? All .NET strings are Unicode
strings. There's no such thing as converting a string to another string
having a different encoding. Such actions only apply to byte arrays.

What you do is
(1) str->bytes(Windows-1252)
(2) convert bytes(Windows-1252) to bytes(UTF-16) pretending they were
bytes(Chinese Simplified)
(3) bytes(UTF-16)->string

I don't see how any chinese character could even survive step (1).

Cheers,

-- 
http://www.joergjooss.de
mailto:news-reply@joergjooss.de


Relevant Pages

  • Re: Chinese characters dont display on excel using asp.net
    ... > string coming from SAP to display Chinese characters on the webpage. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Storing Chinese Characters in Sql Server 2000
    ... First narrow the problem down to whether it is a web interface issue, ... If the column that will hold the Chinese characters is defined as ... the problem is either a browser display issue ... Currently, when I try to store Chinese characters, the ...
    (microsoft.public.sqlserver.server)
  • Re: Chinese characters dont display on excel using asp.net
    ... I get Chinese characters from SAP. ... string coming from SAP to display Chinese characters on the webpage. ... display just fine in Excel but some of them display junk. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Sorry if already posted: eBay; Chinese MM auction
    ... could be chinese characters that aren't being displayed through ebay. ... a major scam, or ebay won't display the characters. ...
    (rec.games.pinball)
  • Run Chinese Program
    ... Pro, but when I click install, it cannot display the ... chinese characters correctly. ... but it still cannot display the chinese character. ...
    (microsoft.public.win2000.setup)