|
Clipboard to table best practices |
Iniciado por anahoret3, 27,ene. 2025 08:35 - 3 respuestas |
| |
| | | |
|
| |
Publicado el 27,enero 2025 - 08:35 |
Greetings, please share your best practices on adding data to table from clipboard. The task is simple, we have table filled programmatically, when we click "Paste Data from Clipboard", data from excel simply should be copied to table.
Preconditions: a) Excel copied column quantity matches table column quantity b) Excel each column data type matches table column data type
The question comes as Clipboard() function returns data with TAB and CR already:

So something simple like (just any example which triggers error to show you that Windev receives data already structured) will not work:

Error:

Thanks in advance |
| |
| |
| | | |
|
| | |
| |
Miembro registrado 62 mensajes |
|
Publicado el 27,enero 2025 - 12:29 |
Hello you have to use FOR EACH STRING and not FOR EACH FOR EACH try to open an HFSQL file and works on it...
xCol1, xCol2, xCol3 is numeric sClipBoardData is string
IF ClipboardFormat(cfText) THEN Trace(Clipboard()) sClipBoardData=Clipboard() FOR EACH STRING sClipB OF sClipBoardData SEPARATED BY CR xCol1=ExtractString(sClipBoardData,1,TAB) xCol2=ExtractString(sClipBoardData,2,TAB) xCol3=ExtractString(sClipBoardData,3,TAB)
Trace("<"+xCol1+">", "<"+xCol2+">", "<"+xCol3+">") END END
Hope this helps Andrea |
| |
| |
| | | |
|
| | |
| |
Publicado el 27,enero 2025 - 15:16 |
Hello
I see your problem, you want to copy information in a text to a table, I have a very dynamic solution for you and already functional
1. You will have to create a multi-line input field to paste the information in TAB and RC, and a table field with a single column is enough COL_A of text type, finally a button field for launching
Here is a program that you can use // EDD (01/25): copy this program into the button field LOCAL cPresse_Papier is ClPresse_Papier cPresse_Papier:m_sChamp = "SSI_Presse_Papier" cPresse_Papier:m_sTable = "TBL_Alphabet" cPresse_Papier:Validation() IF cPresse_Papier:m_bRetour = True THEN cPresse_Papier:Colonne() cPresse_Papier:Lancement() Info("Presse papier copier dans une table réussie.") END
// EDD (01/25): create a new class ClPresse_Papier ClPresse_Papier est une Classe m_bRetour is booléen m_eColonne is entier m_sChamp is string m_sTable is string FIN
// EDD (01/25): create three new methods in the ClPresse_Papier class PROCÉDURE Lancement() LOCAL eEntier is entier sAlphabet, sChaine, sString is string sAlphabet = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" TableSupprimeTout(:m_sTable) FOR i = 1 _TO_ ChaîneOccurrence({:m_sChamp, indChamp}, RC) + 1 sString = ExtraitChaîne({:m_sChamp, indChamp}, i, RC) eEntier = TableAjouteLigne(:m_sTable) IF NoSpace(sString) <> "" THEN FOR j = 1 _TO_ :m_eColonne sChaine = ExtraitChaîne(sAlphabet, j, ",") {:m_sTable + ".COL_" + sChaine, indChamp}[eEntier] = ExtraitChaîne(sString, j, TAB) END END END TableSelectMoins(:m_sTable)
PROCÉDURE Validation() LOCAL :m_bRetour = True IF NoSpace(:m_sChamp) = "" THEN :m_bRetour = False Info("Merci d'initialiser un champ de saisie.") ELSE IF ChampExiste(:m_sChamp) = False THEN :m_bRetour = False Info("Merci de vérifier un champ de saisie introuvable." + RC + "'" + :m_sChamp + "'") ELSE IF {:m_sChamp, indChamp} = "" THEN :m_bRetour = False Info("Merci de copier des textes dans le champ de saisie.") ELSE IF NoSpace(:m_sTable) = "" THEN :m_bRetour = False Info("Merci d'initialiser un champ de table.") ELSE IF ChampExiste(:m_sTable) = False THEN :m_bRetour = False Info("Merci de vérifier un champ de table introuvable." + RC + "'" + :m_sTable + "'") END
PROCÉDURE Colonne() LOCAL sChaine, sString is string = ExtraitChaîne({:m_sChamp, indChamp}, 1, RC) sChaine = "B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" FOR i = 1 _TO_ ChaîneOccurrence(sString, TAB) ChampClone(:m_sTable + ".COL_A", "COL_" + ExtraitChaîne(sChaine, i, ",")) {:m_sTable + ".COL_" + ExtraitChaîne(sChaine, i, ","), indChamp}..Titre = ExtraitChaîne(sChaine, i, ",") END :m_eColonne = ChaîneOccurrence(sString, TAB) + 1
NB: be careful the clipboard comes from an Office Excel document with a column limit of 26, or up to z, but it is dynamic so it is unlimited if you replace the sAlphabet variables up to zzz ...
Best regards Mr.RATSIMANDRESY Niry Aina Eddy |
| |
| |
| | | |
|
| | |
| |
Publicado el 27,enero 2025 - 23:01 |
Thank you guys, both solutions working just fine! |
| |
| |
| | | |
|
| | | | |
| | |
|