|
GRUPOS DE DISCUSSÃO PROFISSIONAL WINDEV, WEBDEV e WINDEV Mobile |
| | | | | |
Pilotage OLE Excel : mise en forme conditionnelle |
Iniciado por Avskyfire, jan., 22 2021 4:20 PM - 3 respostas |
| |
| | | |
|
| |
Publicado em janeiro, 22 2021 - 4:20 PM |
Bonjour à tous,
Après de nombreux essais de syntaxes et plusieurs recherches Google, je me tourne vers ce forum pour résoudre mon problème.
Dans le code qui suit, je ne parviens pas à utiliser la méthode Add afin d'ajouter une mise en forme conditionnelle de type Texte avec l'opérateur "contient" :
objXLApp est un objet automation dynamique SI ObjetActif("Excel.Application") <> Null ALORS objXLApp = ObjetActif("Excel.Application") SINON objXLApp = allouer un objet automation "Excel.Application" FIN SI objXLApp <> Null ALORS objXLApp>>ReferenceStyle=1 objXLApp>>Workbooks>>Open(sFichierExcel) objXLApp>>Range("B:C")>>Select() objXLApp>>Selection>>NumberFormat("jj/mm/aaaa hh:mm:ss") objXLApp>>Range("L:L")>>Select() objXLApp>>Selection>>NumberFormat("jj/mm/aaaa") objXLApp>>Cells>>Select objXLApp>>Cells>>EntireColumn>>AutoFit objXLApp>>Range("H:H")>>Select objXLApp>>Selection>>FormatConditions>>Add(9,0,"ROUGE") objXLApp>>Selection>>FormatConditions(1)>>Font>>Color = -16383844 objXLApp>>Selection>>FormatConditions(1)>>Font>>TintAndShade = 0 objXLApp>>Selection>>FormatConditions(1)>>Interior>>PatternColorIndex = -4105 objXLApp>>Selection>>FormatConditions(1)>>Interior>>Color = 13551615 objXLApp>>Selection>>FormatConditions(1)>>Interior>>TintAndShade = 0 objXLApp>>Selection>>FormatConditions>>Add(9,0,"ORANGE") objXLApp>>Selection>>FormatConditions(2)>>Font>>Color = -16754788 objXLApp>>Selection>>FormatConditions(2)>>Font>>TintAndShade = 0 objXLApp>>Selection>>FormatConditions(1)>>Interior>>PatternColorIndex = -4105 objXLApp>>Selection>>FormatConditions(1)>>Interior>>Color = 10284031 objXLApp>>Selection>>FormatConditions(1)>>Interior>>TintAndShade = 0 objXLApp>>Selection>>FormatConditions>>Add(9,0,"VERT") objXLApp>>Selection>>FormatConditions(3)>>Font>>Color = -16752384 objXLApp>>Selection>>FormatConditions(3)>>Font>>TintAndShade = 0 objXLApp>>Selection>>FormatConditions(3)>>Interior>>PatternColorIndex = -4105 objXLApp>>Selection>>FormatConditions(3)>>Interior>>Color = 13561798 objXLApp>>Selection>>FormatConditions(3)>>Interior>>TintAndShade = 0 objXLApp>>Range("A1")>>Select objXLApp>>Activeworkbook>>Save() objXLApp>>Quit() Libérer objXLApp FIN
L'erreur qui apparaît est la suivante :
Vous avez appelé la méthode Automation 'Add'. En tentant d'invoquer la méthode <Add> ou de lire la propriété <Add>, l'objet Automation/ActiveX a renvoyé l'erreur suivante : 'Erreur 8002000F, Un paramètre requis a été omis : ' En tentant d'invoquer la méthode <Add>, l'objet Automation/ActiveX a renvoyé l'erreur suivante : 'Erreur 8002000F, Un paramètre requis a été omis : ' En tentant de lire la propriété <Add>, l'objet Automation/ActiveX a renvoyé l'erreur suivante : 'Erreur 80020003, Le membre demandé n'existe pas' En tentant d'écrire la propriété <Add>, l'objet Automation/ActiveX a renvoyé l'erreur suivante : 'Erreur 80020003, Le membre demandé n'existe pas'
La documentation de Microsoft n'est pas très claire sur ce cas de figure (condition de type texte), et je ne vois vraiment pas quel est le problème. Les valeurs des constantes ne serait-elles pas les bonnes ?
Je précise que le reste du code fonctionnait déjà avant que j'ajoute la partie sur les mises en forme conditionnelles.
Si quelqu'un à une idée, ça m'aiderait pas mal. Merci de m'avoir lu en tout cas. |
| |
| |
| | | |
|
| | |
| |
Publicado em janeiro, 25 2021 - 9:31 AM |
J'ai pu utiliser un fichier de constantes Excel qu'on m'a fourni, mais cela ne change rien les valeurs étaient bien les bonnes. Le code d'ajout ressemble maintenant à cela :
objXLApp>>Selection>>FormatConditions>>Add(xlTextString, xlContains, "ROUGE") objXLApp>>Selection>>FormatConditions(1)>>Font>>Color = -16383844 objXLApp>>Selection>>FormatConditions(1)>>Font>>TintAndShade = 0 objXLApp>>Selection>>FormatConditions(1)>>Interior>>PatternColorIndex = xlPatternAutomatic objXLApp>>Selection>>FormatConditions(1)>>Interior>>Color = 13551615 objXLApp>>Selection>>FormatConditions(1)>>Interior>>TintAndShade = 0
Si jamais quelqu'un d'autre est inspiré, n'hésitez pas je suis preneur de la moindre info |
| |
| |
| | | |
|
| | |
| |
Membro registado 945 mensagems Popularité : +102 (110 votes) |
|
Publicado em janeiro, 26 2021 - 5:25 PM |
Bonjour Je viens de faire un petit test qui vous permettra peut-être de trouver la solution. Le fichier Excel contient dans la colonne « A » -3 -2 -1 0 1 2 3 4 5 6 Et je veux que si : cellule < 0 fond rouge 0 < cellule < 5 fond orange 5 < cellule fond vert
xl est un objet automation dynamique FichierExcel est une chaîne = ComplèteRep(fRepExe()) + "Condition.xlsx"
IF not fFichierExiste(FichierExcel) THEN Trace(ChaîneConstruit("Erreur fichier :%1inconnu !", FichierExcel)) RETOUR END
xl = allouer un objet automation "Excel.Application" IF xl = Null THEN Trace("Erreur 'Excel.application' n'est pas installé sur ce poste !") RETOUR END
xl>>Visible = EnModeTest()
xl>>WorkBooks>>Open(FichierExcel) WHEN EXCEPTION IN xl>>Worksheets("Feuil1")>>Activate DO Erreur("Feuille inconnue !") xl>>ActiveWorkbook>>Close() xl>>Quit() Libérer xl END
xl>>Cells>>FormatConditions>>Delete
xl>>Range("A1:A20")>>Select()
xl>>Selection>>FormatConditions>>Add(xlCellValue, xlLess, "=0") xl>>Selection>>FormatConditions(xl>>Selection>>FormatConditions>>Count)>>SetFirstPriority xl>>Selection>>FormatConditions(1)>>Interior>>PatternColorIndex = xlAutomatic xl>>Selection>>FormatConditions(1)>>Interior>>Color = 255 xl>>Selection>>FormatConditions(1)>>Interior>>TintAndShade = 0 xl>>Selection>>FormatConditions(1)>>StopIfTrue = False
xl>>Selection>>FormatConditions>>Add(xlCellValue, xlBetween, "=0", "=5") xl>>Selection>>FormatConditions(xl>>Selection>>FormatConditions>>Count)>>SetFirstPriority xl>>Selection>>FormatConditions(1)>>Interior>>PatternColorIndex = xlAutomatic xl>>Selection>>FormatConditions(1)>>Interior>>ThemeColor = xlThemeColorAccent4 xl>>Selection>>FormatConditions(1)>>Interior>>TintAndShade = 0n0.599963377788629 xl>>Selection>>FormatConditions(1)>>StopIfTrue = False
xl>>Selection>>FormatConditions>>Add(xlCellValue, xlGreater, "=5") xl>>Selection>>FormatConditions(xl>>Selection>>FormatConditions>>Count)>>SetFirstPriority xl>>Selection>>FormatConditions(1)>>Interior>>PatternColorIndex = xlAutomatic xl>>Selection>>FormatConditions(1)>>Interior>>ThemeColor = xlThemeColorAccent6 xl>>Selection>>FormatConditions(1)>>Interior>>TintAndShade = 0n0.599963377788629 xl>>Selection>>FormatConditions(1)>>StopIfTrue = False
xl>>ActiveWorkbook>>Save() xl>>ActiveWorkbook>>Close() xl>>Quit() Libérer xl
-- «Nos clients sont nos meilleurs beta testeur.» H. Mintzberg «Un programme informatique fait ce que vous lui avez dit de faire, pas ce que vous voulez qu'il fasse» Troisième loi de Greer |
| |
| |
| | | |
|
| | |
| |
Membro registado 945 mensagems Popularité : +102 (110 votes) |
|
Publicado em janeiro, 26 2021 - 8:12 PM |
pour votre problème on peut le contourner ainsi :
xl est un objet automation dynamique FichierExcel est une chaîne = ComplèteRep(fRepExe()) + "Condition.xlsm"
IF not fFichierExiste(FichierExcel) THEN Trace(ChaîneConstruit("Erreur fichier :%1inconnu !", FichierExcel)) RETOUR END
xl = allouer un objet automation "Excel.Application" IF xl = Null THEN Trace("Erreur 'Excel.application' n'est pas installé sur ce poste !") RETOUR END
xl>>Visible = EnModeTest()
xl>>WorkBooks>>Open(FichierExcel) WHEN EXCEPTION IN xl>>Worksheets("Feuil1")>>Activate DO Erreur("Feuille inconnue !") xl>>ActiveWorkbook>>Close() xl>>Quit() Libérer xl END
xl>>Cells>>FormatConditions>>Delete
xl>>Range("C1:C10")>>Select()
Formula1 est une chaîne = [ =CHERCHE(" ROUGE ";C1) ]
xl>>Selection>>FormatConditions>>Add(xlExpression, Null, Formula1) xl>>Selection>>FormatConditions(xl>>Selection>>FormatConditions>>Count)>>SetFirstPriority xl>>Selection>>FormatConditions(1)>>Font xl>>Selection>>FormatConditions(1)>>Font>>Color = -16383844 xl>>Selection>>FormatConditions(1)>>Font>>TintAndShade = 0 xl>>Selection>>FormatConditions(1)>>StopIfTrue = False
xl>>ActiveWorkbook>>Save() xl>>ActiveWorkbook>>Close() xl>>Quit() Libérer xl
-- «Nos clients sont nos meilleurs beta testeur.» H. Mintzberg «Un programme informatique fait ce que vous lui avez dit de faire, pas ce que vous voulez qu'il fasse» Troisième loi de Greer |
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|