You are here:

FoxPro/pl. help for program


can you create a program for me for simple text file reading and getting desired output.i.e.desired characters column wise in excel sheet.
thanks in advance.

Hi, Dilip

   Although an excel spreadsheet can be directly accessed with FoxPro if the appropriate ODBC driver is installed, I don't know if you have that capability.  However, there is an easy way to access the data without it; convert the file to a database format.  The conversion can be done from within either program...


Using the Excel menu, select:   "File"   Then, "Save As..."
From the "Save as" dialog box, select the output file type as .DBF (I believe the option specifies "dBase database," but I don't have Excel installed to confirm this.)  
(NOTE: You didn't specify your version, but if you are using a recent version of Visual FoxPro, it will prompt you to do a one-time conversion when you USE the file.)


Create an empty FoxPro table with a field structure to match to columns in the spreadsheet.
(NOTE: Columns with dates should be created as "Character" fields in the structure to avoid conversion issues.)

Once created, add records to it with the APPEND FROM command:

    APPEND FROM <filename.xls> TYPE XL5
    APPEND FROM <filename.xls> TYPE XLS

Whether you use XL5 or XLS depends on the version of the Excel file.  Try the XL5 first, it will work in most cases.  If the file is a very old version of Excel, maybe XLS will work if the first one fails.

When the table is ready (from either method), simply open it as any other FoxPro table to produce your report.


All Answers

Answers by Expert:

Ask Experts


Fred Frase


Questions about development only. No installation or hardware specific questions, please. Your first step in requesting assistance should be to identify the version of FoxPro you are using. I can write short functions but, PLEASE do not ask me to write programs for you.


Nearly 30 years professional programming experience using FoxPro (FoxBase through VFP 9) or other xbase language, primarily in Windows environments.

Completed a 1,000 hour diploma course in programming at International Academy of Ohio (subsequently merged with Southern Ohio College).

©2017 All rights reserved.