tStart = seconds() handle=fcreate('myDummy.txt') For ix=1 to 100 For jx=1 to 100 =fwrite(handle,iif(jx=1,'',chr(9))+; 'This is row '+transform(ix)+',Column '+transform(jx)) Endfor =fwrite(handle,chr(13)+chr(10)) Endfor =fclose(handle) _Cliptext=FileToStr('myDummy.txt') Erase ('myDummy.txt') ? seconds()-tStart oExcel = createobject('Excel.Application') With oExcel .Workbooks.Add tStart = seconds() .Activeworkbook.Activesheet.Range('A1').Pastespecial() .visible = .T. Endwith ? seconds()-tStart *!* oExcel = createobject('Excel.Application') *!* With oExcel *!* .Workbooks.Add *!* With .Activeworkbook.Activesheet *!* tStart = seconds() *!* For ix=1 to 100 *!* For jx=1 to 100 *!* .Cells(ix,jx)='This is row '+transform(ix)+',Column '+transform(jx) *!* Endfor *!* Endfor *!* Endwith *!* .visible = .T. *!* Endwith *!* ? seconds()-tStartVFP part sounds to be dummy ? :) Not at all, it's the fastest part in code. You could still make that part with tables in many different ways (ie: Application.Datatoclip(), copy to .. type delimited with tab etc). It's Excel side that's slow. Try uncommenting the commented part and commenting others to see cell by cell is more than 20 times slower.
Create cursor myCursor ; (myString c(10), myNumber i, myDate d, myDatetime t, myFloat b(4)) Rand(-1) For ix = 1 to 100 Insert into myCursor values ; (sys(2015),; int(rand()*100),; int(rand()*100)+date(),; int(rand()*86400*100)+datetime(),; rand()*1000) Endfor lcExcelFile = 'myExcelTest.xls' Copy to (lcExcelFile) type xls oExcel = createobject('Excel.Application') With oExcel .Workbooks.Open(sys(5)+curdir()+lcExcelFile) && Open xls we just saved * Select all data (Currentregion) and copy to clipboard .ActiveWorkBook.ActiveSheet.Cells(1,1).CurrentRegion.Copy .ActiveWorkBook.Saved = .T. && File not changed - not needed really .Workbooks.Add && Create a new workbook as target .ActiveWorkBook.ActiveSheet.Range("D14").PasteSpecial() && Paste * Empty clipboard so we don't need extra coding to prevent dummy * 'You placed data on clipboard ...' dialog from excel _Cliptext = '' .Workbooks(1).Close(.F.) && Close our intermediate workbook .Visible = .T. && Show excel EndwithPS:Note that in all samples oExcel.visible is the last call. Experiment how it slows down if you place it earlier in code (but while developing it's wise to have it at top so it would be easier to close excel in case an error in code occurs)