Code Tips

The free code tips, advice and tricks contained here are for the programme developer. The information contained here will help improve your programme skills. lets code less, code better. 

Our target: Small tips, solve big problems.

Import into Excel using CSV File having Unicode Data Options

Problems:
I am facing a small prblem with Excel and Unicode Data. I am writing data into a CSV file from the database with VB.NET using a Stream Writer object with UTF8 Encoding. This data is Unicode data with Chinese characters with UTF8 encoding. When I open it in Excel (office XP) it does not show the Chinese characters properly, they are converted into ASCII Characters.

Tips
The prblem is that Excel does not or cannot interpret UTF 8 encoding.
So i played a trick on it and encoded the Data using the 16 bit encoding. Which goes something like this :

Dim otxtEncoding As System.Text.Encoding = New System.Text.UnicodeEncoding()
Dim oSW As StreamWriter = New StreamWriter ("c:\UTC16.txt", True, otxtEncoding)

This was correctly interpreted by Excel when the file was saved as a csv file.


12/11/2007 4:17:00 AM Category .Net

People who read this, also read...


Back