Solved

Determine if Unicode reading characters in Excel file

Posted on 2011-03-22
2
533 Views
Last Modified: 2012-05-11
I have a problem when I open data from an Excel file to a DBF file in FoxPro.

I want to create a VB.NET application to see if any Unicode characters exist in an excel file before I convert to a dbf.  (Stop using dbf is not an option)

I know I can determine the character set using .NET, but I dont have time to research.  Anyone have a solution or sample code using "System.Text.Encoding"

Basically, I want to: read an excel file using .NET.  I would then evaluate each character in the excel file.  If the character is not a match for Ascii character, or is Unicode character set, then I would indicate what character was found, in what column, in what row, and exactly what character #.  This record could then be extracted by someone before it is converted to dbf.
0
Comment
Question by:handyjay
2 Comments
 
LVL 11

Accepted Solution

by:
lenordiste earned 500 total points
ID: 35193242
here s a nice discussion on how to do this. Look for the first answer:
http://stackoverflow.com/questions/4459571/how-to-recognize-if-a-string-contains-unicode-chars

also, a similar topic has been already discussed in EE:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22513239.html
0
 

Author Comment

by:handyjay
ID: 35193535
Thanks, in the meantime I wrote something similar, which may or maynot be as effective.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim lerr As New List(Of String)
        Dim dt As Data.DataTable = loadDtfromExel()

        Dim rowId As Integer = 1
        For Each row As Data.DataRow In dt.Rows
            Dim sSearch As String = row("Name").ToString
            ' Create two different encodings.
            Dim ascii As System.Text.Encoding = System.Text.Encoding.ASCII
            Dim unicode As System.Text.Encoding = System.Text.Encoding.Unicode

            ' Convert the string into a byte array.
            Dim unicodeBytes As Byte() = unicode.GetBytes(sSearch)

            ' Perform the conversion from one encoding to the other.
            Dim asciiBytes As Byte() = System.Text.Encoding.Convert(unicode, ascii, unicodeBytes)

            ' Convert the new byte array into a char array and then into a string.
            Dim asciiChars(ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length) - 1) As Char
            ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0)
            Dim asciiString As New String(asciiChars)

            ' Display the strings created before and after the conversion.
            Console.WriteLine("Original string: {0}", sSearch)
            Console.WriteLine("Ascii converted string: {0}", asciiString)

            For Each c As Char In asciiString
                If c = "?" Then
                    lerr.Add("RowID: " & rowId.ToString & "  Name: " & sSearch)
                End If

            Next

            rowId += 1
        Next

    End Sub

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now