save the clipboard to array

save the clipboard to array

Postby Natter » Tue May 28, 2024 12:39 pm

I select a rectangular part (2x50) of the Excel sheetand save it to the clipboard .
How can I read data from a buffer into a two-dimensional array (2x50) ?
Natter
 
Posts: 1186
Joined: Mon May 14, 2007 9:49 am

Re: save the clipboard to array

Postby leandro » Tue May 28, 2024 1:38 pm

Hola buenos días, nosotros lo hacemos de la siguiente manera, con el apoyo de una función publicada en el foro.

Espero te sirva

Code: Select all  Expand view

******************************
*Pegamos los items desde excel
******************************
Function pegarItemsExcel()
Local oClp
Local cTxt := space(0)
Local aTipoDato := {"C","C","N","N","C","N"}
Local aValido := {}
Local aLna := {}
Local nBien := 0
Local hLinea := hash()
Local aDato := {}
//Abrimos el portapapeles y recuperamos el ultimo texto registrado
oClp = TClipBoard():New()
oClp:Open()
cTxt = oClp:GetText()
oClp:Close()           
//Recuperamos el array que biene desde el portapapeles
aText := ParsePasteText( cTxt ) //Funcion en funciones.prg
//Validamos que la informaci�n contenida en el array este bien
FOR i:=1 TO len( aText )
    if len(aText[i])==6
        nBien := 0
        aLna := aText[i]
        FOR y:=1 TO len(aLna)
            if valtype(aLna[y])==aTipoDato[y]
                nBien++
            endif
        NEXT
        if nBien==6
            AADD(aValido,aLna)
        endif
    endif
NEXT

************************************************************
*Convierte la información en array para pegar en los xbrowse
*Funcion descargada de foro de FW
************************************************************
Function ParsePasteText( cText, cDelim, aTipo )
LOCAL n, j, nCols, uValue := "", aText := {}
DEFAULT cDelim := Chr(9)
DEFAULT aTipo := {}
IF LEN(cText) = 0
   MsgInfo("No hay registros para copiar","Error Datos")
   RETURN {}
ENDIF

cText := StrTran( cText, CRLF, Chr(10) )
aText := hb_aTokens( cText, Chr(10) )

FOR n := 1 TO LEN( aText )
    aText[ n ] := hb_aTokens( aText[ n ], cDelim)
NEXT

IF ! EMPTY( aText )
   CursorWait()
   nCols       := LEN( aText[ 1 ] )
   FOR n := 1 TO LEN( aText )-1
       FOR j := 1 TO nCols
           uValue := if(len(aTipo)==0,uCharToVal( aText[ n ][ j ]),if(aTipo[j]=="C",;
                    cvaltochar( aText[ n ][ j ]),uCharToVal( aText[ n ][ j ])))
           aText[n,j] := uValue  
       NEXT j
   NEXT n
   CursorArrow()
ENDIF

RETURN aText


 
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1627
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: save the clipboard to array

Postby Natter » Tue May 28, 2024 2:05 pm

I get it, thanks!
Natter
 
Posts: 1186
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 60 guests