Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel won't open VFP tables
Message
From
18/05/2006 13:05:41
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
18/05/2006 10:57:22
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01117509
Message ID:
01123301
Views:
24
This message has been marked as the solution to the initial question of the thread.
>>>It has bugged me for a long time that Excel does not offer the possibility to open VFP files directly. It does read dBase files, but to do that you must copy tables TYPE FOX2X.
>>>
>>>Has anybody mentioned this to MS before?
>>>
>>>Alex
>>
>>Alex,
>>Which version of Excel doesn't read VFP tables directly (VFPOLEDB is considered direct,no?).
>>Cetin
>
>Hi Cetin,
>
>I want to import a cursor that has long names into Excel. Can you explain how to do it using VFPOLEDB? I will be using automation and then saving it as a bonafide xls file.
>
>TIA,
>
>Alex
* Create a table with LNF fieldnames
* in a directory with an LNF path
Local lcLNFDir
lcLNFDir = "c:\An LNF path"
Md (m.lcLNFDir)
Create Database ( Addbs(m.lcLNFDir)+"myDatabase" )
Select cust_id As CustomerID, ;
  company As "ThisIsAnLNF_Company_Name_of_customer", ;
  contact As "ThisIsAnLNF_Contact_FirstName_and_LastName_of_customer", ;
  city, Region, country ;
  from (_samples+'Data\Customer') ;
  into Table ( Addbs(m.lcLNFDir)+"myLNFTable" ) ;
  database ( Addbs(m.lcLNFDir)+"myDatabase" )
Close Databases All

* Send data to excel
* PS: This is one of the many ways
VFP2Excel(Addbs(m.lcLNFDir)+"myDatabase.dbc",;
  'select * from myLNFTable',;
  "ThisIsVFPData")

Erase ( Addbs(m.lcLNFDir)+"*.*" )
Rd (m.lcLNFDir)

Function VFP2Excel
  Lparameters tcDataSource, tcSQL, tcSheetName
  Local loConn As AdoDB.Connection, ;
    loRS As AdoDB.Recordset,;
    lcTempRs As String, ;
    lcTemp As String, ;
    oExcel As Excel.Application

  lcTempRs = Sys(5)+Curdir()+Sys(2015)+'.rst'
  loConn = Createobject("Adodb.connection")
  loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+m.tcDataSource
  loConn.Open()
  loRS = loConn.Execute(m.tcSQL)
  loRS.Save(m.lcTempRs)
  loRS.Close
  loConn.Close
  loRS.Open(m.lcTempRs)

  oExcel = Createobject("Excel.Application")
  With oExcel
    .WorkBooks.Add
    .Visible = .T.
    With .ActiveWorkBook.ActiveSheet
      .Name = m.tcSheetName
      .QueryTables.Add( loRS, .Range("A1")).Refresh()
    Endwith
  Endwith
  loRS.Close
  Erase (m.lcTempRs)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform