Convert xls to FoxPro dbf?

caseylee used Ask the Experts™

I have the data file in both Excel and txt format. I need to convert it into FoxPro dbf format. In Exel XP (on Win2K), there are three options for dbf format: db II, db III and db IV.

For FoxPro, which one should I use? Or should I use something entirely different.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Use DBase III if you are writing it from Excel to a file for opening in VFP.
You could also use the following to append the data directly from the XLS file.
You can try type XLS first and then XL5 and XL8 if necessary.  You can also specify which sheet to open with thw XL5 and XL8 types.

Here is some code that is taken from a form that does exactly what you need.  The problem with xls to DBF is that depending on the data fields that are in the XLS the will transform to a large numeric field.  This field will be the days that have passed since 12-31-1899 (the turn of the 19th century).  If you import the xls file and you see dates that appear to be of this nature just derive the true date by adding these days to the date equilvalent of this field

Store CTOD('12/31/1899') + Field to NewDate.  Other than that issue this code is pretty straight forward.

STORE (sys(5) + SYS(2003)) to Hold_Path  && Root
SET default to &Import_Path  && My import Directory
m.FileName  = GetFILE([xls,XLS],'Get XLS Input Data','Select',0,'Generate New Accounts')  && File Dialog
IF !EMPTY(M.FileName)  && Got an xls file
    Set default to &Import_Path  && set path to write
    Store JUSTSTEM(M.FileName) to TheName  && dbf name
    Store 'IMPORT FROM ' + M.FileName + ' TYPE XL8 AS 1252' to Command
    Select &TheName
SET default to &Hold_path && Reset path

Any other questions you can e-mail me at



Dear Slink9,

The Excell cannot be used to translate to .dbf because it does not transformed the time correctly. It always add the date of 1/1/1900 to the time, no matter what format the time column is.

CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Could you provide a sample XL file.

That is a DBF file's DATETIME format.  You can pull the time out of it by doing a TTOC() on the field.
In Foxpro 7.0 DBase IV version opens/imports correctly.  When modifying it,VFP will ask you if you want to convert it to a current version.  You will want to copy (COPY AS)it to at least the default which is "1252".

  You can export it to an older version of Excel, such as Excel 95 or 97.  Then import it into Foxpro.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial