I found updating a lot of cells with OLE is real slow so I use windows clipboard to store the data and paste it into spreadsheet. This is very fast. I am sure you can do the reverse.
Select the cell range or sheet and copy them to windows clipboard.
Read clipboard into a (x)Harbour variable.
Here is a sample program I did some time ago to demonstrate how much faster copy and paste is.
Towards the end I added a couple of lines to show how to copy from excel to clipboard
and save it to a file that you can use "append from cFile delim with tab".
- Code: Select all Expand view
#define GTI_CLIPBOARDDATA 15
FUNCTION MAIN()
LOCAL oExcel, oSheet
LOCAL nRow
LOCAL nCounter, nStart, nSeconds, nSecOle, nSecClip
LOCAL cMemo, cData
oExcel = CREATEOBJECT( "Excel.Application" )
oExcel:WorkBooks:Add()
oSheet = oExcel:ActiveSheet
nRow := 1
oSheet:Cells( nRow, 1 ):Value = "Counter"
oSheet:Cells( nRow, 2 ):Value = "Date"
oSheet:Cells( nRow, 3 ):Value = "Row"
nCounter := 1
nStart := nCounter
// ------------------ Start Cell by Cell
nSeconds := seconds()
DO WHILE nCounter < 2000
oSheet:Cells( nCounter+nRow, 1 ):Value = nCounter
oSheet:Cells( nCounter+nRow, 2 ):Value = date()-nCounter
oSheet:Cells( nCounter+nRow, 3 ):Value = nCounter-1
nCounter++
ENDDO
nSecOle := seconds()-nSeconds
nRow += nCounter+2
oSheet:Cells( nRow, 1 ):Value = "Counter"
oSheet:Cells( nRow, 2 ):Value = "Date"
oSheet:Cells( nRow, 3 ):Value = "Row"
// ------------------ Start Clipboard
nSeconds := seconds()
nCounter := 1
nStart := nCounter
cMemo := ''
DO WHILE nCounter < 2000
// build record
cMemo += ltrim( str( nCounter ) )
cMemo += chr(9)+dtoc( date()-nCounter )
cMemo += chr(9)+ltrim( str( nCounter+nRow-1 ) )
cMemo += chr(10)
nCounter++
// update sheet every 1000 records or eof() if using dbf
IF mod( nCounter, 1000 ) = 0 // .or. eof()
GTSetClipboard( cMemo )
oSheet:Cells( nRow+nStart, 1 ):Select()
oSheet:paste()
nStart := nCounter
cMemo := ''
ENDIF
ENDDO
// ------------------ Results on Screen
nSecClip := seconds()-nSeconds
? 'Ole = '+ltrim(str(nSecOle))
? 'Clip = '+ltrim(str(nSecClip))
wait
// Example of getting data from spreadsheet
// and saving to a text file so that it can be
// appended to data file with
// append from cFile delim with tab
oSheet:Range("A1:C1000"):copy()
cData := hb_gtInfo( GTI_CLIPBOARDDATA )
memowrit( 'test2.txt', cData )
oExcel:Visible = .T.
RETURN( nil )
function gtsetclipboard( cText )
if cText == nil
cText := ''
endif
hb_gtInfo( GTI_CLIPBOARDDATA, cText)
return nil