When I try to export a large amount of data using the toexcel() method, the program throws an error and crashes.
The error occurs on the line oSheet:Paste() inside the toexcel() method.
Does anyone have a solution?
I also added sysrefresh() after this line, but it still didn’t work.
Toexcel method crashes when you work with big data
Toexcel method crashes when you work with big data
Birol Betoncu
[email protected]
Using Harbour, FWH 26.08, BCC77
- alerchster
- Posts: 154
- Joined: Mon Oct 22, 2012 4:43 pm
Re: Toexcel method crashes when you work with big data
Many thanks for your reply,
Yes it works when I use this, but is very slow (Same as when I use oExcel := CREATEOBJECT( "Excel.Application" ))
Toexcel method (without using oBrw:lExcelCellWise := .t.) uses bulk insert and it is very fast.
I think some changes needed in toexcel() method to achieve this.
Birol Betoncu
[email protected]
Using Harbour, FWH 26.08, BCC77
Re: Toexcel method crashes when you work with big data
Code: Select all | Expand
C:\FWH\samples\XBRUTF01.PRG
Re: Toexcel method crashes when you work with big data
betoncu wrote: Thu Nov 20, 2025 4:35 pmMany thanks for your reply,
Yes it works when I use this, but is very slow (Same as when I use oExcel := CREATEOBJECT( "Excel.Application" ))
Toexcel method (without using oBrw:lExcelCellWise := .t.) uses bulk insert and it is very fast.
I think some changes needed in toexcel() method to achieve this.
Hi,
Try adding this function every 3 pastes, for example
Code: Select all | Expand
FUNCTION MemoryCompact()
hb_GCAll(.t.); SysRefresh()
Sleep(.1)
hb_GCAll(.t.); SysRefresh()
RETURN NIL
- mauri.menabue
- Posts: 184
- Joined: Thu Apr 17, 2008 2:38 pm
Re: Toexcel method crashes when you work with big data
Hi All
assume it's something related to accented letters into CLIPBOARD.
You can use this function:
*---------------------------------------------------------------------------------------
Function StrToUtf8( cOriginal )
*---------------------------------------------------------------------------------------
LOCAL c := HB_STRTOUTF8( cOriginal, "UTF8")
LOCAL cFinal := UTF16TOUTF8( strToWide( c ) )
return cFinal
1) The function : StrToUtf8( takes as input a cOriginal string (probably in local or ANSI encoding).
2) HB_STRTOUTF8() is a Harbour function that converts a string from a source code page
(the current runtime code page) to UTF-8.
Here, the second parameter, "UTF8," indicates the destination.
Result: c is a UTF-8 string, but still handled as a normal Harbour CHARACTER.
3) strToWide( c ) takes the UTF-8 string and converts it to a wide string (UTF-16).
UTF16TOUTF8() converts that wide string back to a clean UTF-8.
It's essentially a two-step process: UTF-8 → UTF-16 → UTF-8.
This normalizes the string, eliminating code page ambiguities or non-standard characters.
to modify the toexcel method in Xbrowse
Code: Select all | Expand
do while nRow <= ( nDataRows + 1 ) .and. lContinue
if ! Empty( cText )
cText += CRLF
endif
cText += ::ClpRow( .t., aCols )// lContinue := ( ::Skip( 1 ) == 1 )
lContinue := nRow < ( nDataRows + 1 ) .and. ( ::Skip( 1 ) == 1 )
nRow ++
Code: Select all | Expand
if Len( cText ) > 16000
::oClp:SetText( StrToUtf8( cText ) ) <--------------------------------------------------------
oSheet:Cells( nPasteRow, 1 ):Select()
oSheet:Paste()
::oClp:Clear()
cText := ""
nPasteRow := nRow
endif
If ( nRow - 2 ) % nStep == 0
if Eval( bProgress, nRow - 2, nDataRows ) == .f.
Exit
endif
SysRefresh()
endif
enddo
if ! Empty( cText )
::oClp:SetText( StrToUtf8( cText ) ) <----------------------------------------------------
oSheet:Cells( nPasteRow, 1 ):Select()
oSheet:Paste()
::oClp:Clear()
endif
Eval( bProgress, nDataRows, nDataRows )
SysRefresh()
...TIA