save the clipboard to array

Post Reply
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

save the clipboard to array

Post by Natter »

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) ?
User avatar
leandro
Posts: 1744
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia
Has thanked: 34 times
Been thanked: 10 times
Contact:

Re: save the clipboard to array

Post by leandro »

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

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

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 24.09 ] [ xHarbour 64 bits) ]
Natter
Posts: 1241
Joined: Mon May 14, 2007 9:49 am

Re: save the clipboard to array

Post by Natter »

I get it, thanks!
Post Reply