FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Toexcel method crashes when you work with big data
Posts: 130
Joined: Sat Oct 08, 2005 09:38 PM
Toexcel method crashes when you work with big data
Posted: Thu Nov 20, 2025 03:38 PM

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.

Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
Posts: 137
Joined: Mon Oct 22, 2012 04:43 PM
Re: Toexcel method crashes when you work with big data
Posted: Thu Nov 20, 2025 04:00 PM
Regards



Ing. Anton Lerchster
Posts: 130
Joined: Sat Oct 08, 2005 09:38 PM
Re: Toexcel method crashes when you work with big data
Posted: Thu Nov 20, 2025 04:35 PM

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
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Toexcel method crashes when you work with big data
Posted: Thu Nov 20, 2025 05:20 PM
C:\FWH\samples\XBRUTF01.PRG
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Toexcel method crashes when you work with big data
Posted: Thu Nov 20, 2025 10:08 PM
betoncu wrote:

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.

Hi,

Try adding this function every 3 pastes, for example

FUNCTION MemoryCompact()
hb_GCAll(.t.); SysRefresh()
Sleep(.1)
hb_GCAll(.t.); SysRefresh()
RETURN NIL
Posts: 181
Joined: Thu Apr 17, 2008 02:38 PM
Re: Toexcel method crashes when you work with big data
Posted: Fri Nov 21, 2025 04:22 PM

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

           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 ++

              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

Continue the discussion