Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Problem with DBF and Excel

Hello!

I'm trying to import some dbf files into ms excel 2003, using the MS windows XP ODBC driver for DBF.

All goes ok, but when showing the data, special characters like ,,,,... are not showed, but instead %,,...garbage appears. I actually know that the data is correct in the dbf files. I saw it using a dbf viewer, called... Dbf Viewer ;) which uses native access to dbf data browsing and editing. In fact, it asks me whether to switch on/off a feature called "use OEM characters" which, turned off, shows the sam as excel...that annoying garbage.

From this I suppose that in the connection process, a parameter to specify the character encoding is sent, but this parameter is not available to be modified in the ODBC DBF connection driver configuration. At least in microsoft one...

At this point I've two options, both of them too unclear...

- Use a third party driver, which allows me to change the char encoding method (driver which I cannot find. Actually I can't find any third party driver for dbf).

-Find a way to specify the char encoding to the standard microsoft odbc dbf driver (Way that I'm also unable to find)

Now I'm testing with excel, but the goal is to get read/write access from an app which I'm doing probably with delphi or vb.net using ODBC to save time.

Well...I hope somebody can help me :)

Thanks a lot and regards!

McRuffian
[1476 byte] By [McRuffian] at [2007-11-11 8:42:35]
# 1 Re: Problem with DBF and Excel
How does the data look if you open the dBase file using the Jet OLEDB provider and dBase ISAM driver?

Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset

'Open folder where dBase files are located
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:\My Documents\dBase;Extended Properties=dBase 5.0;"

rs.Open "Select * from MyDBase.dbf", cnn, adOpenStatic, adLockBatchOptimistic
pclement at 2007-11-11 23:46:58 >
# 2 Re: Problem with DBF and Excel
MMM...bad luck. With that connection string, the data shown contains the same garbage instead of the special chars.
McRuffian at 2007-11-11 23:48:03 >
# 3 Re: Problem with DBF and Excel
Do you know what character set was used when this database was created?
pclement at 2007-11-11 23:49:02 >
# 4 Re: Problem with DBF and Excel
MMmm I'm afraid I don't know it, because the dbf is generated by a billing third party propietary software.
McRuffian at 2007-11-11 23:50:07 >
# 5 Re: Problem with DBF and Excel
Does the DBF Viewer utility provide this information by any chance?
pclement at 2007-11-11 23:51:03 >
# 6 Re: Problem with DBF and Excel
I've been watching the options, but the only option I found is the one I told earlier: Use OEM or ANSI characaters, which is the responsible for the garbage showing or not. (ANSI shows no garbage, while OEM does).
But there's not any summary or info section with char encoding information.
McRuffian at 2007-11-11 23:52:02 >
# 7 Re: Problem with DBF and Excel
Hi,

I am experiencing a similar Problem. I have a DBF file which, when I open it in FoxPro, contains a lot of "garbage" instead of text. When I select Export with Foxpro, and write the Tables to a CSV-File, the csv File actualy contains the correct Texts (Chinese in my case).

I am working on a VB(A) application, which is to retrieve text from different DBF files. The DBF-Files contain different languages/codepages (Russian/Chinese,etc..). The VB-App writes the text into seperate TXT-Files.
I have tried reading out the DBF files by use of "Microsoft.Jet.OLEDB.4.0" and the "Windows XP dBase Driver", both result in retrieving the (same) garbage as displayed in Foxpro. I am now trying to figure out how Foxpro is able to convert the garbage into unicode Text files, but until now have failed to succeed.

hope anyone can tell me how to do the last step (garbage to Text) in VB,

Thanks,

Stephan
StephanR at 2007-11-11 23:53:11 >