Copy to disk and read: 0.857 - 0.894 seconds _Vfp.DataToClip : 9.243 - 9.546 secondsvfpDataToClip(,,3) was not returning the content right anyway, before doing a comparison it should be right in the first place (vfpDataToClip() adds an extra column).
Clear * Create a test cursor Create Cursor testcursor (Rcno i,cType c(10), nType i, dType d) Rand(-1) For ix = 1 To 200000 && Create 200000 recs cursor Insert Into testcursor Values ; (Recco()+1,Sys(2015), Int(Rand()*1000), Date()-Int(Rand()*100)) Endfor Locate Start = Seconds() lnRowsPerCopy = Floor(65000/Fcount()) Dimension aHeader[1,FCOUNT()] For ix = 1 To Fcount() aHeader[1,m.ix] = Proper(Field(m.ix)) Endfor Wait Window Nowait "Pls wait sending data to Excel..." oExcel = Createobject("Excel.application") With oExcel .workbooks.Add && Add a new workbook .Visible = .T. lnMaxRows = .ActiveWorkBook.ActiveSheet.Rows.Count && Get max row count lnNeededSheets = Ceiling( Reccount() / (m.lnMaxRows - 1) ) && 1 row header ? "Total Pages : "+Padr(lnNeededSheets,3) With .ActiveWorkBook If m.lnNeededSheets > .sheets.Count .sheets.Add(,.sheets(.sheets.Count),; m.lnNeededSheets - .sheets.Count) && Add new sheets after old ones Endif For ix =1 To m.lnNeededSheets .WorkSheets(m.ix).Name = "Page "+Padl(m.ix,3,"0") Endfor For ix=1 To m.lnNeededSheets With .WorkSheets(m.ix) .Activate .Range(.cells(1,1), .cells(1,Fcount())).Value = GetArrayRef('aHeader') Endwith For jx = 1 To Ceiling((m.lnMaxRows - 1) / m.lnRowsPerCopy) lnRowStart = Recno() - (m.ix - 1) * (m.lnMaxRows - 1) + 1 lnRowEnd = Min(m.lnRowStart + m.lnRowsPerCopy-1, m.lnMaxRows) Dimension aTrans[m.lnRowEnd - m.lnRowStart + 1,FCOUNT()] Copy Next (m.lnRowEnd - m.lnRowStart + 1) To Array aTrans lnCopied = _Tally Dimension aTrans[m.lnCopied,FCOUNT()] With .WorkSheets(m.ix) .Range(.cells(m.lnRowStart,1), .cells(m.lnRowStart + m.lnCopied-1,Fcount())).Value = GetArrayRef('aTrans') Endwith If !Eof() Skip Else Exit Endif Endfor ? "Page no : "+; padl(m.ix,3)+; "/"+; padr(m.lnNeededSheets,3)+ ; " Elapsed : ",Seconds() - Start Endfor Endwith .sheets.Item(1).Activate Endwith ? "Total Elapsed : ",Seconds() - Start Function GetArrayRef(tcArrayName) Return @&tcArrayNameWhile this is one of the fastest available approaches, not the fastest.
Clear * Create a test cursor Create Cursor testcursor (Rcno i,cType c(10), nType i, dType d) Rand(-1) For ix = 1 To 200000 && Create 200000 recs cursor Insert Into testcursor Values ; (Recco()+1,Sys(2015), Int(Rand()*1000), Date()-Int(Rand()*100)) Endfor Locate Start = Seconds() Local tableName tableName = 'MyExcelData'+Sys(2015) Copy To (ForcePath(m.tableName, Sys(2023))) Local loStream As AdoDb.Stream loStream = GetDataAsAdoStream("Provider=VFPOLEDB;Data Source="+Sys(2023), "select * from " + m.tableName) Erase (ForcePath(ForceExt(m.tableName,'*', Sys(2023))) Local oExcel oExcel = Createobject("Excel.Application") With m.oExcel .DisplayAlerts = .F. .Workbooks.Add .Visible = .T. * Send the data - copy to replacement VFP2ExcelVariation(m.loStream, .ActiveWorkBook.ActiveSheet.Range('A1')) Endwith ? "Total Elapsed : ",Seconds() - Start Function VFP2ExcelVariation(toStream, toRange, tcHeaders) Local loRS As AdoDb.Recordset,ix loRS = Createobject('Adodb.Recordset') m.loRS.Open( m.toStream ) m.toRange.Offset(1,0).CopyFromRecordSet( m.loRS ) && Copy data starting from headerrow + 1 * Use first row for headers Local Array aHeader[1] For ix=1 To Iif( !Empty(m.tcHeaders), ; ALINES(aHeader, m.tcHeaders,1,','), ; m.loRS.Fields.Count ) m.toRange.Offset(0,m.ix-1).Value = ; Iif( !Empty(m.tcHeaders), ; aHeader[m.ix], ; Proper(m.loRS.Fields(m.ix-1).Name) ) m.toRange.Offset(0,m.ix-1).Font.Bold = .T. Endfor m.loRS.Close() Endfunc Procedure GetDataAsAdoStream(tcConnection, tcSQL) Local loStream As 'AdoDb.Stream', ; loConn As 'AdoDb.Connection', ; loRS As 'AdoDb.Recordset' loStream = Createobject('AdoDb.Stream') loConn = Createobject("Adodb.connection") loConn.ConnectionString = m.tcConnection m.loConn.Open() loRS = loConn.Execute(m.tcSQL) m.loRS.Save( loStream ) m.loRS.Close m.loConn.Close Return m.loStream EndprocAs per the timings, I took some time to test them TAB, Array and VFP2Excel approach with the same data: