473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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?

Thanks,
Chanda.

Nov 19 '05 #1
7 4270
c.*****@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:ne********@joergjooss.de
Nov 19 '05 #2
Hi Joerg,
It would be helpful, if you send me the piece of code.

With the code that I have written, it displays the Chinese characters
perfectly fine on the web page but it does behave randomly on the excel
sheet. I have tried different kinds of codes, but the above one was the
only one that could work.

I would really appreciate if you send me the code.

Thanks,
Chanda.

Nov 19 '05 #3
In the above declaration: Public Function ToSCUnicode(ByVal str As
String) As String

str is the Chinese string coming from SAP, which if displayed on the
webpage, displays junk characters. But after manipulating the above
string in ToSCUnicode function, the Chinese characters display totally
fine on the web page. After exporting on to excel, sometimes Chinese
characters display fine, sometimes, they display junk. But the
characters ALWAYS display fine on web page. So the above code works for
web pages.

Nov 19 '05 #4
c.*****@gmail.com wrote:
In the above declaration: Public Function ToSCUnicode(ByVal str As
String) As String

str is the Chinese string coming from SAP, which if displayed on the
webpage, displays junk characters.
Is it really junk or do you just use the wrong encoding on your page?
But after manipulating the above
string in ToSCUnicode function, the Chinese characters display totally
fine on the web page.
Then whatever comes from the SAP backend seems to be already broken.
After exporting on to excel, sometimes Chinese
characters display fine, sometimes, they display junk. But the
characters ALWAYS display fine on web page. So the above code works
for web pages.


And still fixes a problem that shouldn't be there in the first place ;-)

Cheers,

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #5
c.*****@gmail.com wrote:
Hi Joerg,
It would be helpful, if you send me the piece of code.
With the code that I have written, it displays the Chinese characters
perfectly fine on the web page but it does behave randomly on the
excel sheet.


Regardless whether your conversion method is required, you still need
to make sure that the spreadsheet you create uses the correct character
encoding. What do you actually create? A CSV file or a true XLS?

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #6
Well this is what is confusing me.
1) I get Chinese characters from SAP. They don't get displayed fine on
ASP.NET web pages. So I have to use TSCUnicode function to convert the
string coming from SAP to display Chinese characters on the webpage.

2) Now EXACTLY the same webpage (where chinese characters) are
displaying fine, gets exported to excel. Surprisingly, few records from
display just fine in Excel but some of them display junk.

3) It is an XLS file, not a CSV. The spredasheet has correct character
encoding.

If I could attach the screenshots, I could have explained it better.

Chanda.

Nov 19 '05 #7
c.*****@gmail.com wrote:
Well this is what is confusing me.
1) I get Chinese characters from SAP. They don't get displayed fine on
ASP.NET web pages. So I have to use TSCUnicode function to convert the
string coming from SAP to display Chinese characters on the webpage.


How do you receive the characters from SAP? As raw bytes? As .NET
strings?

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Antonio Ooi | last post by:
Hi, Probably due to my 'Language for non-Unicode Setting' in Regional Settings, my ASP page keeps outputing the date format as Chinese Simplified characters when issuing say, <%=Now()%>. In...
4
by: see_mun_lee | last post by:
I use asp to develop a web page to read an excel file containing Chinese Character then display it in the web page. Unfortunately, I cant display it!!! it will display (?????????). <META...
1
by: zxo102 | last post by:
Hi there, I am trying to put data including Chinese Characters into Excel through python. But I got some problems. Here is my sample code: ################################################## #...
8
by: pabv | last post by:
Hello all, I am having a few issues with encoding to chinese characters and perhaps someone might be able to assist. At the moment I am only able to see chinese characters when displayed as...
4
by: K | last post by:
I've an XML file in UTF-8. It contains some chinese characters ( both simplified chinese and traditional chinese). In loading the XML file with MSXML parser, I used the below code to retrieve...
1
by: Chris Yan | last post by:
Hi All I have an excel sheet with Chinese characters in them. I'm using the OLEBE 4.0 Jet Driver in C# Microsoft Visual Studio 2005 to read from the Excel sheet and then enter into mySQL...
15
by: Lorenzo Stella | last post by:
Hi all, I haven't experienced functional programming very much, but now I'm trying to learn Haskell and I've learned that: 1) in functional programming LISTS are fundmental; 2) any "cycle" in FP...
5
by: Figmo | last post by:
I'm having a problem working with foreign characters (well....foreign to me anyway) I have a textbox control on a form. The font is set to MS Arial Unicode. If I use the Chinese input method...
13
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.