Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: gerrit broekhuis
  Where is gerrit broekhuis?
 holten
 Netherlands
 gerrit broekhuis
 Tags
Subject: excel 2007 to dbf
Thread ID: 252571 Message ID: 252571 # Views: 38 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: ODBC, ADO and OLEDB
Date: Friday, February 05, 2010 3:27:43 PM         
   


Hi,

On microsoft.com I found the following code for converting Excel XLS file to a table.
This code doesn't seem te be working in my case. Connection to the ODBC Excel driver fails, perhaps due to 64-bit Windows 7 ultimate?
I know there are 2 ODBC's when using the 64-bit OS.

*-----------------------------------
* AUTHOR: Trevor Hancock
* CREATED: 02/15/08 04:55:31 PM
* ABSTRACT: Code 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 Connectivity Components
*-----------------------------------
LOCAL lcXLBook AS STRING, lnSQLHand AS INTEGER, ;
    lcSQLCmd AS STRING, lnSuccess AS INTEGER, ;
    lcConnstr AS STRING
CLEAR

lcXLBook = [C:\SampleWorkbook.xlsx]

lcConnstr = [Driver=] + ;
    [{Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};] + ;
    [DBQ=] + lcXLBook

IF !FILE( lcXLBook )
    ? Excel file not found
    RETURN .F.
ENDIF
*-- Attempt a connection to the .XLSX WorkBook.
*-- 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 = SQLSTRINGCONNECT( lcConnstr )

*-- Connect successful if we are here. Extract data...
lcSQLCmd = [Select * FROM "Sheet1$"]
lnSuccess = SQLEXEC( lnSQLHand, lcSQLCmd, [xlResults] )
? [SQL Cmd Success:], IIF( lnSuccess > 0, 'Good!', 'Failed' )
IF lnSuccess < 0
    LOCAL ARRAY laErr[1]
    AERROR( laErr )
    ? laErr(3)
    SQLDISCONNECT( lnSQLHand )
    RETURN .F.
ENDIF

*-- Show the results
SELECT xlResults
BROWSE NOWAIT
SQLDISCONNECT( lnSQLHand )


Any idea how to get this working? Any alternative solution to save a xls file to dbf is also welcome.

Regards, Gerrit



COMPLETE THREAD
excel 2007 to dbf Posted by gerrit broekhuis @ 2/5/2010 3:27:43 PM
RE: excel 2007 to dbf Posted by Glen Villar @ 2/5/2010 3:43:33 PM
RE: excel 2007 to dbf Posted by gerrit broekhuis @ 2/5/2010 4:35:33 PM
RE: excel 2007 to dbf Posted by Stefan Wuebbe @ 2/5/2010 4:10:11 PM
RE: excel 2007 to dbf Posted by gerrit broekhuis @ 2/5/2010 4:38:00 PM
RE: excel 2007 to dbf Posted by Anders Altberg @ 2/5/2010 4:38:06 PM
RE: excel 2007 to dbf Posted by Anders Altberg @ 2/5/2010 5:28:25 PM