Professional Documents
Culture Documents
Importing Data From A Microsoft Excel 2007 Workbook Using Visual FoxPro 9
Importing Data From A Microsoft Excel 2007 Workbook Using Visual FoxPro 9
Article ID: 949529 - Last Review: February 21, 2008 - Revision: 1.1
Importing data from a Microsoft Excel 2007 workbook using Visual
FoxPro 9.0
Source: Microsoft Support
RAPID PUBLISHING
RAPID PUBLISHING ARTIC LES PROVIDE INFORMATION DIREC TLY FROM WITHIN
THE MIC ROSOFT SUPPORT ORGANIZATION. THE INFORMATION C ONTAINED HEREIN IS C REATED IN RESPONSE TO
EMERGING OR UNIQUE TOPIC S, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
Action
You have a Microsoft Excel 2007 workbook (.XLSX). You want to import data from it into a Microsoft Visual FoxPro
(VFP) table using VFP.
Resolution
1. Export the Excel sheet(s) as comma delimited files (.C SV) and use the IMPORT command or the Import Wizard
inside VFP to import the file(s).
2. Write custom VFP OLE automation code to automate Excel and extract the data to VFP.
3. Use the Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb) ODBC driver included with the 2007 Office System
Driver: Data C onnectivity C omponents package to access and extract data from the Excel workbook, either through
a VFP Remote View or programmatically, as in the following sample code:
*-----------------------------------
* AUTHOR: Trevor Hancock
* C REATED: 02/15/08 04:55:31 PM
* ABSTRAC T: C ode demonstrates how to connect to
* and extract data from an Excel 2007 Workbook
* using the "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)"
* from the 2007 Office System Driver: Data C onnectivity C omponents
*-----------------------------------
LOC AL lcXLBook AS STRING, lnSQLHand AS INTEGER, ;
lcSQLC md AS STRING, lnSuccess AS INTEGER, ;
lcC onnstr AS STRING
C LEAR
lcXLBook = [C :\SampleWorkbook.xlsx]
IF !FILE( lcXLBook )
? [Excel file not found]
RETURN .F.
ENDIF
*-- Attempt a connection to the .XLSX WorkBook.
support.microsoft.com/default.aspx?s… 1/2
18/11/2010
p
Importing data from a Microsoft Excel …
*-- NOTE: If the specified workbook is not found,
*-- it will be created by this driver! You cannot rely on a
*-- connection failure - it will never fail. Ergo, success
*-- is not checked here. Used FILE() instead.
lnSQLHand = SQLSTRINGC ONNEC T( lcC onnstr )
More Information
DISC LAIMER
TO THE MAXIMUM EXTENT PERMITTED BY APPLIC ABLE LAW, MIC ROSOFT AND/OR ITS SUPPLIERS DISC LAIM AND
EXC LUDE ALL REPRESENTATIONS, WARRANTIES, AND C ONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY,
INC LUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR C ONDITIONS OF TITLE, NON
INFRINGEMENT, SATISFAC TORY C ONDITION OR QUALITY, MERC HANTABILITY AND FITNESS FOR A PARTIC ULAR
PURPOSE, WITH RESPEC T TO THE MATERIALS.
APPLIES TO
Keywords: kbnomt kbrapidpub KB949529
support.microsoft.com/default.aspx?s… 2/2