Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to copy a cursor to a spreadsheet
Message
De
23/03/2007 07:20:12
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
22/03/2007 20:11:36
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01175581
Message ID:
01207550
Vues:
85
After loCon.Open() try:
  loRS = loConn.Execute("select * from "+m.lcTemp)
  With toSheet
   FOR ix=1 TO loRS.Fields.Count
     .Cells(1,m.ix).Value = PROPER(loRs.Fields(m.ix-1).Name)
   endfor
   .Range('A2').CopyFromRecordSet( loRS )
  Endwith
  loRS.Close
Cetin

>Hi Cetin,
>
>I'm hoping you can help. I found your post in this thread while I was searching for a similar solution, and it has been working great. Now, though I am using the same approach and getting an error with a certain cursor, and I don't know enough about ADO to find the cause of the problem.
>
>
>CCMD.Multiple-step operation generated errors. Check each status value.Microsoft OLEDB Persistence Provider
>
>
>
>This error occurs in the VFP2Excel function on this line:
>
>
>loRS.Save(m.lcTempRs)
>
>
>
>
>
>>
>>LOCAL oExcel,ix,lcCursorName
>>LOCAL ARRAY sheetNames[5]
>>Select emp_id,First_Name,Last_Name,;
>>  Title,Notes ;
>>  from (_samples+'\data\employee') ;
>>  into Cursor crsToExcel1 ;
>>  nofilter
>>
>>Select cust_id,company,contact,Title,country ;
>>  from (_samples+'\data\customer') ;
>>  into Cursor crsToExcel2 ;
>>  nofilter
>>
>>Select * ;
>>  from (_samples+'\data\orders') ;
>>  into Cursor crsToExcel3 ;
>>  nofilter
>>
>>Select * ;
>>  from (_samples+'\data\orditems') ;
>>  into Cursor crsToExcel4 ;
>>  nofilter
>>
>>Select * ;
>>  from (_samples+'\data\products') ;
>>  into Cursor crsToExcel5 ;
>>  nofilter
>>
>>sheetNames[1] = "Employees"
>>sheetNames[2] = "Customers"
>>sheetNames[3] = "Orders"
>>sheetNames[4] = "Order Details"
>>sheetNames[5] = "Products"
>>
>>
>>oExcel = Createobject("Excel.Application")
>>With oExcel
>>  .DisplayAlerts = .F.
>>  .Workbooks.Add
>>  .Visible = .T.
>>  With .ActiveWorkBook
>>    For ix = 1 To 5
>>      lcCursorName = 'crsToExcel'+Ltrim(Str(m.ix))
>>      If .sheets.Count < m.ix
>>        .sheets.Add(,.sheets(.sheets.Count)) && Add new sheet
>>      ENDIF
>>      .WorkSheets(m.ix).Name = sheetNames[m.ix]
>>      VFP2Excel(m.lcCursorName, .WorkSheets(m.ix),"A1" )
>>    ENDFOR
>>    .WorkSheets(1).Activate
>>  Endwith
>>Endwith
>>
>>Function VFP2Excel
>>  Lparameters tcCursorName, toSheet, tcTargetRange
>>  tcCursorName = Iif(Empty(m.tcCursorName),Alias(),m.tcCursorName)
>>  tcTargetRange = Iif(Empty(m.tcTargetRange),'A1',m.tcTargetRange)
>>  Local loConn As AdoDB.Connection, loRS As AdoDB.Recordset,;
>>    lcTempRs, lcTemp, oExcel
>>  lcTemp = Forcepath(Sys(2015)+'.dbf',Sys(2023))
>>  lcTempRs = Forcepath(Sys(2015)+'.rst',Sys(2023))
>>  Select (m.tcCursorName)
>>  Copy To (m.lcTemp)
>>  loConn = Createobject("Adodb.connection")
>>  loConn.ConnectionString = "Provider=VFPOLEDB;Data Source="+Sys(2023)
>>  loConn.Open()
>>  loRS = loConn.Execute("select * from "+m.lcTemp)
>>  loRS.Save(m.lcTempRs)
>>  loRS.Close
>>  loConn.Close
>>  Erase (m.lcTemp)
>>  loRS.Open(m.lcTempRs)
>>
>>  With toSheet
>>    .QueryTables.Add( loRS, .Range(m.tcTargetRange)).Refresh()
>>  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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform