Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exporting To Excel
Message
From
19/05/2005 17:59:35
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
19/05/2005 14:45:13
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 2000 SP4
Network:
Windows NT
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01015815
Message ID:
01016046
Views:
14
>>Can you step through the table and copy each record? Something like:
>>
>>SET SAFETY OFF
>>CREATE TABLE foxtest (ca c(10), cb c(10), cc c(10))
>>PRIVATE icounter
>>FOR icounter = 1 TO 1000
>>    sele foxtest
>>    APPEND BLANK
>>    REPLACE ca WITH "a" + ALLTRIM(STR(icounter))
>>    REPLACE cb WITH "b" + ALLTRIM(STR(icounter))
>>    REPLACE cc WITH "c" + alltrim(STR(icounter))
>>    icounter = icounter + 1
>>ENDFOR
>>
>>RELEASE oExcel
>>lcXLSFile = 'foxtest'
>>lcXLSFile = ForceExt(lcXLSFile, "XLS")
>>
>>lcRange = "a1:c1000"
>>oExcel = CREATEOBJECT("excel.application")
>>WITH oExcel
>>   .WorkBooks.add()
>>   WITH .ActiveWorkbook.ActiveSheet.RANGE(lcRange)
>
>Here's my speed tip - just today it took just a few seconds to insert 15300 rows into an Excel sheet. I'm assuming a one-line range is selected, and then I expand it as needed.
>
>
	_vfp.DataToClip(,,3)
>	* remove first line from clipboard, contains column names
>	c=_cliptext
>	_cliptext=Strtran(_cliptext, Mline(_cliptext,1)+chr(13),"")
>
>	If RECCOUNT() > 1
>		oExcel.Application.CutCopyMode = .t.
>		oRng = oExcel.Range(oExcel.Cells(.Row + 1, 1), oExcel.Cells(.Row + reccount() - 1, 1))
>		oRng.EntireRow.Insert
>	ENDIF
>	oRng.select()
>	oExcel.selection.PasteSpecial()
>	_cliptext=c
>
>
>And that's it. I may have been off by one here, as I had to rename a few variables to fit the names in the example, and remove some framework related code, but with a couple of tweaks this should work - and it's quite a bit faster than filling cells one by one.
>
>
>   ENDWITH
>>   .save(lcXLSFile)
>>ENDWITH
>>
>>USE IN foxtest
>>oExcel.quit()
>>
>>

Dragan,
Not to discourage you but I already have n different versions of this (n versions was a result of search for speed) and it gets slower and slower as rowcount increases. It seems to be working not bad for the first 64K records (first sheet) but then with each new sheet timing almost is doubled.
PS:

Copy to tempfile.txt delimited with tab
_cliptext = FileToStr(...)
erase tempfile.txt && Instead of datatoclip
....
.Range('A1').PasteSpecial && Instead of calculating target range

works better with this approach.
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