?
Solved

Determine if Unicode reading characters in Excel file

Posted on 2011-03-22
2
Medium Priority
?
543 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
lenordiste earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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