Exporting FoxPro Table Structures and Index Definitions to Excel

The COPY STRUCTURE EXTENDED command is a flexible method for capturing schema details from a Visual FoxPro table. It converts field meatdata into rows within a dedicated DBF, which can then be routed to Excel without manual transcription.

Given a table CUSTOMERS.DBF:

Structure for table:          C:\DATA\CUSTOMERS.DBF
Number of data records:       2034
Date of last update:          05/12/2022
Code Page:                    1252
 Field  Field Name            Type                        Width      Dec    Index   Collate     Nulls       Next       Step
     1  CUST_ID               Integer (AutoInc)               4               Asc   Machine        No          1          1
     2  FULL_NAME             Character                      40                                    No
     3  BALANCE               Numeric                         8        2                           No
     4  IS_ACTIVE             Logical                         1                                    No
** Total **                                                  54

Switch to the data directory and issue:

SET DEFAULT TO C:\DATA
USE customers
COPY STRUCTURE EXTENDED TO cust_schema

Open the resulting cust_schema.dbf, which contains rows for each field with columns for field name, type, width, decimals, null support, and more. Export it to Excel with the native TYPE XL5 clause:

USE cust_schema
COPY TO CustStructure.xls TYPE XL5

This produces an Excel workbook ready for review. For capturing index definitions, ATAGINFO() returns array data about the tags on the currently selected work area. The following script iterates through that array and persists it to a cursor, then to a XLS file:

LOCAL nTagCount, i
CREATE CURSOR idx_export (;
    TagName     C(128), ;
    TagType     C(12),  ;
    KeyExpr     C(240), ;
    Filter      C(240), ;
    Order       C(12),  ;
    Collation   C(24)   ;
)

IF !USED('customers')
    USE customers IN 0
ENDIF
SELECT customers
nTagCount = ATAGINFO(aTags)

FOR i = 1 TO nTagCount
    INSERT INTO idx_export VALUES (;
        aTags[i, 1], aTags[i, 2], aTags[i, 3], ;
        aTags[i, 4], aTags[i, 5], aTags[i, 6] ;
    )
ENDFOR

SELECT idx_export
COPY TO IndexInfo.xls TYPE XL5

The workbook will contain columns for tag name, type (Primary, Candidate, Regular, etc.), key expression, filter condition, order direction, and collating sequence. These exports provide raw documentation that can be used for schema migration, audit, or rebuilding database objects on a different platform.

Tags: foxpro Excel Schema dbf indexing

Posted on Wed, 07 Oct 2026 16:52:30 +0000 by CaseyLiam