#cs Description ****************************************************************************************** Func_Tableau.au3 Version 0.0.1.1 du 19/03/2014 Création d'un tableur sur une GUI Création d'un tableur aux dimensions d'un Array, importation de ses données. Création d'un tableur aux dimensions d'une BDD, importation de ses données (limites: 50 lignes, 15 colonnes). Formatage et fusion des cellules Modifications, calculs, formules dans les cellules Importation de données d'un tableau Excel Exportation du tableau en tableau Word, image sur Word ou Array Principe de base: Les cellules sont désignées ainsi: La première ligne ou colonne est 1 Les formules commencent par = e.g. =<1,3>+<2,5> Les cellules contenant une formule sont colorées, seul le résultat est visible Testé sous PC Win 7 et XP Formules ********************************************************************************************* Différentes formules utilisables dans le tableau: = 3 + 2 (+,-,/,* etc... retourne 5) = Mon mot (retourne "Mon mot") = + + + ... e.g. =<1,1>+<4,2> (+,-,/,* etc...) = (Concaténation des contenus des cellules) = SUM (Somme des valeurs entre ces deux cellules. Valide sur une ligne ou une colonne) e.g. =sum<1,1><1,5> = MOY (Moyenne des valeurs entre ces deux cellules. Valide sur une ligne ou une colonne) = MAX (Valeur maximale entre ces deux cellules. Valide sur plusieurs lignes ou colonnes)e.g. =max<1,1><5,5> = MIN (Valeur minimale entre ces deux cellules. Valide sur plusieurs lignes ou colonnes) = + (additionne les deux cellules)(+,-,/,* etc...) = * 3 (+,-,/,* etc...) = * 3 + (+,-,/,* etc... Rmq: l'ordre des calculs est respecté mais les parenthèses ne sont pas supportées) Note: ces formules sont utilisables avec AutoFormule() ou directement dans le tableau en utilisant MsgArray() Fonctions ********************************************************************************************* TableSetFormat() -Formate le tableau. Fonction obligatoire à placer en premier CreateTableau() -Crée un "pseudo" tableau constitué de Inputs MsgArray() -Renvoie l'ID du tableau et calcule les formules (ID du tableau = Input) ReturnMsgArray -Retourne la valeur de MsgArray() sans relancer cette fonction (Renvoie l'ID du tableau) DeleteTable() -Détruit le tableau Fusion() -Fusionne horizontalement les cellules InsertArray() -Création d'un nouveau tableau à partir d'un Array 1D ou 2D InsertSqlite() -Création d'un nouveau tableau à partir d'une BDD Sqlite ImportExcel() -Importe les données d'un tableau Excel ExportArray -Exporte le tableau dans un Array ExportBitmapToWord() -Exporte l'image du tableau dans un document Word ExportWord() -Exporte le tableau avec ses fusions de cellules dans un document Word AutoFormule() -Entre automatiquement des formules dans le tableau AutoStyle() -Défini le format d'une cellule IncrementeFormuleV() -Incrémente une formule dans une colonne ValeurRetour() -Retour de valeur d'une cellule avec ou sans condition (=,<,>,<=,>=) ******************************************************************************************************* #ce #include-Once #include #include ; GDIPlus.au3, WinAPI.au3 #include ; File.au3, Array.au3, InetConstants.au3, FileConstants.au3 #include Global $array, $nMsg, $IDchoix Global $repond ;~ ========================================================================================================= ;~ Func TableSetFormat($iRound = "",$size = "",$weight = "",$attribute = "", $fontname = "",$style = "") ;~ Description: Formate le tableau. Toutes les variables sont optionnelles mais la Fonction est obligatoire e.g. TableSetFormat() ;~ $iRound: Nombre de décimals après la virgule pour les valeurs numériques. Par défaut 2 ;~ $ySize: Fontsize >>>> Voir GUICtrlSetFont() ;~ $yWeight: The weight of the font ;~ $yAttribut: Font attributes ;~ $yFontname: Name of the font to use. ;~ $yStyle: Defines the style of the control. >>>> Voir GUICtrlSetStyle() ;~Rmq: Les styles à utiliser sont $ES_CENTER, $ES_LOWERCASE, $ES_RIGHT, $ES_UPPERCASE ;~ Note: TableSetFormat() se place obligatoirement avant CreateTableau()à sa création ;~ Pour import ou modifications de données, on réutilise TableSetFormat() après la modification Func TableSetFormat($iRound = "",$size = "",$weight = "",$attribute = "", $fontname = "",$style = "") If $iRound = "" Then $iRound = 2 Global $roundFmsg = $iRound Global $size1 = $size Global $weight1 = $weight Global $attribute1 = $attribute Global $fontname1 = $fontname Global $style1 = $style Global $controlSetFormat = 1 If IsArray($array) Then For $y = 0 To UBound($array,1) - 1;hauteur For $i = 0 To UBound($array,2) - 1;largeur GUICtrlSetFont($array[$y][$i],$size1,$weight1,$attribute1,$fontname1) GUICtrlSetStyle($array[$y][$i],$style1) $valCellTSF = GUICtrlRead($array[$y][$i]) If $valCellTSF > "" And Number($valCellTSF) <> 0 Then $valCellTSF = Round($valCellTSF,$iRound) $valCellTSF = StringFormat("%." & $iRound & "f",$valCellTSF) GUICtrlSetData($array[$y][$i],$valCellTSF) EndIf Next Next EndIf EndFunc ;========================================================================================================= ;~ Func CreateTableau($Handle,$Tleft,$Ttop,$NBligne,$NBcol,$widthCell,$heightCell) ; Description: crée un tableau composé de Inputs indépendants ou interdépendants ; L'ensemble des control ID est retourné dans $array[Nombre de lignes][Nombre de colonnes] ;~ $Handle: Windows handle as returned by GUICreate() ;~ $Tleft: The left side of the first control. if omitted, the controls are centered in the window ;~ $Ttop: The top of the first control. if omitted, the controls are centered in the window ;~ $NBligne: Number of controls in height ;~ $NBcol: Number of controls in width ;~ $widthCell: The width of the controls, if omitted, the controls occupy the width of the window ;~ $heightCell: The height of the controls, if omitted, the controls occupy the height of the window ;Note: si la largeur ou la hauteur des Inputs dépassent la fenêtre, le tableau n'est pas construit. ;~ Si la fonction TableSetFormat()n'existe pas ou créée après cette fonction , le tableau n'est pas construit. Func CreateTableau($Handle,$Tleft,$Ttop,$NBligne,$NBcol,$widthCell,$heightCell) If $controlSetFormat <> 1 Then Return SetError(1,0,0) ;vérifie si TableSetFormat() existe If $Handle = "" Then Return SetError(1,0,0) Global $myarray[0][0] Global $array[$NBligne][$NBcol] Local $pos = WinGetPos($Handle) If $widthCell = "" Then $widthCell = ($pos[2]- 8 - $Tleft) / $NBcol EndIf If $heightCell = "" Then $heightCell = ($pos[3]- 30 - $Ttop) / $NBligne EndIf If $Tleft = "" Then $Tleft = ( ($pos[2]- 8) - ($NBcol * $widthCell ) ) /2 EndIf If $Ttop = "" Then $Ttop = ( ($pos[3]- 30) - ($NBligne * $heightCell) ) /2 EndIf If $NBcol * $widthCell > $pos[2] - 8 - $Tleft Then Return SetError(2, 0, 0) If $NBligne * $heightCell > $pos[3] - 30 - $Ttop Then Return SetError(2, 0, 0) For $y = 0 To $NBligne - 1;hauteur $Tleft1 = $Tleft For $i = 0 To $NBcol - 1;largeur $array[$y][$i] = GUICtrlCreateInput("", $Tleft1, $Ttop, $widthCell, $heightCell);les touches GUICtrlSetTip(-1,$y + 1 & " | " & $i + 1) GUICtrlSetFont(-1,$size1,$weight1,$attribute1,$fontname1) GUICtrlSetStyle(-1,$style1) $Tleft1 += $widthCell Next $Ttop += $heightCell $Tleft1 = $Tleft Next EndFunc ;CreateTableau($Handle,$Tleft,$Ttop,$NBligne,$NBcol,$widthCell,$heightCell) ;================================================================================================== ;~ MsgArray($nMsg) ;Description: Vérifie si ID control fait parti du tableau par retour de GUIGetMsg() ; effectue les calculs et retourne la valeur du ID control du tableau ;~ $nMsg: valeur de GUIGetMsg ;Syntaxe: Case MsgArray($nMsg) pour une utilisation de Switch...Case...EndSwitch ;~ Réussite: Retourne $IDchoix = ID control ;~ Echec: Retourne $IDchoix = 0 ;~ Note: La valeur de MsgArray($nMsg) est récupérable par Func ReturnMsgArray() Func MsgArray($nMsg) If IsArray($array) = 1 Then $ID1 = $array[0][0] For $d = UBound($array,2) - 1 To 0 Step -1 $IDfin = $array[UBound($array,1) - 1][$d] If $IDfin > "" Then ExitLoop;si fusion cherche dernière valeur ID dans la dernière ligne Next If $nMsg > $ID1 - 1 And $nMsg < $IDfin + 1 Then $repond = GUICtrlRead($nMsg) formule($roundFmsg) $IDchoix = $nMsg Else $IDchoix = 0 EndIf EndIf Return $IDchoix EndFunc ;~ =================================================================================================== ;~ Func ReturnMsgArray() ;~ Description: Retourne la valeur MsgArray() sans relancer cette fonction. ;~ ReturnMsgArray() se place aprés la fonction MsgArray() ;~ Réussite: ReturnMsgArray() = ID control du tableau ;~ Echec: ReturnMsgArray() = 0 ;~ Note: si ReturnMsgArray() > 0 le tableau a été modifié. Une nouvelle procédure peut être envisagée Func ReturnMsgArray() If $IDchoix <> 0 Then $returnID = $IDchoix Return $returnID Else Return 0 EndIf EndFunc;ReturnMsgArray() ;~ ===================================================================================================== ;~ Func DeleteTable() Func DeleteTable() If Not IsArray($array) Then Return SetError(1,0,0) If $array[0][0] = "" Then Return SetError(1,0,0);$array existe mais vide For $i = 0 To UBound($array,1) - 1 For $y = 0 To UBound($array,2) - 1 If $array[$i][$y] <> "" Then GUICtrlDelete($array[$i][$y]) Next Next EndFunc ;DeleteTable() ;====================================================================================================== ;~ Func Fusion($handle,$ligne,$colonne,$nbcells) ;~ Description: Fusionne les cellules horizontalement ;~ $handle: Windows handle as returned by GUICreate() ;~ $ligne: La ligne concernée 1 étant première ;~ $colonne: La colonne concernée 1 étant première ;~ $nbcells: Nombre de cellules fusionnées à partir du croisement ligne colonne vers la droite ;~ Note: C'est une pseudo fusion car seule, la première cellule est allongée, les autres sont détruites. Le retour des ID est modifié sur $array Func Fusion($handle,$ligne,$colonne,$nbcells) If Not IsArray($array) Then Return SetError(2, 0, 0) If $ligne < 1 Then Return SetError(2, 0, 0) If $colonne < 1 Then Return SetError(2, 0, 0) If $nbcells < 1 Then Return SetError(2, 0, 0) If UBound($array,2) = 1 Then Return SetError(1, 0, 0);array 1D >> pas de fusion Local $largeTT = "" If $colonne + $nbcells -1 <= UBound($array,2) Then For $m = 0 To $nbcells - 1 $ID = $array[$ligne - 1][$colonne - 1 + $m] $pos = ControlGetPos($handle,"","[CLASS:Edit; ID:" & $ID & "]") If @error Then Return SetError(2, 0, 0) $largeTT += $pos[2] If $m > 0 Then GUICtrlDelete($ID);Supprime les $input $array[$ligne - 1][$colonne - 1 + $m] = "";mise à jour de l'array EndIf Next GUICtrlSetPos($array[$ligne - 1][$colonne - 1 ],Default,Default,$largeTT,Default) Else MsgBox(0,"Error","La fusion excède la taille maximale") EndIf EndFunc ;Fusion($handle,$ligne,$colonne,$nbcells) ;===================================================================================================== ;~ Func InsertArray($Iarray,$Handle,$Tleft,$Ttop,$widthCell,$heightCell,$ligneSup = 0,$ColSup = 0) ;Description: Importe un array dans un nouveau tableau ;~ $Iarray: Array à importer ;~ $Handle: Windows handle as returned by GUICreate() ;~ $Tleft: Bord gauche du tableau par rapport au Gui ;~ $Ttop: Sommet du tableau par rapport au Gui ;~ $widthCell: Largeur des cellules ;~ $heightCell: Hauteur des cellules ;~ $ligneSup: (option) lignes suplémentaires dans le bas du tableau ;~ $ColSup: (option) Colonnes suplémentaires à droite du tableau ;Note: si la largeur ou la hauteur des Inputs dépassent la fenêtre, le tableau n'est pas construit. ;~ Si la fonction TableSetFormat()n'existe pas ou est créée après cette fonction , le tableau n'est pas construit. Func InsertArray($Iarray,$Handle,$Tleft,$Ttop,$widthCell,$heightCell,$ligneSup = 0,$ColSup = 0) If $Iarray = "" Then Return SetError(1,0,0) $NBcolImport = UBound($Iarray,2) Local $1D = 0 If $NBcolImport = 0 Then ;pour les arrays 1D $1D = 1 $NBcolImport = $NBcolImport + 1 EndIf $NBligneImport = UBound($Iarray,1) $NBligneImport1 = $NBligneImport + $ligneSup ;ajout lignes $NBcolImport1 = $NBcolImport + $ColSup ;ajout colonnes If IsArray($array) Then DeleteTable();si $array existe, le tableau existe >> delete CreateTableau($Handle,$Tleft,$Ttop,$NBligneImport1,$NBcolImport1,$widthCell,$heightCell) If @error Then Return SetError(1,0,0) If $1D = 0 Then For $i = 0 To $NBligneImport - 1 For $y = 0 To $NBcolImport - 1 GUICtrlSetData($array[$i][$y],$Iarray[$i][$y]) Next Next Else For $i = 0 To $NBligneImport - 1 GUICtrlSetData($array[$i][0],$Iarray[$i]) Next EndIf EndFunc ;InsertArray($Iarray,$Handle,$Tleft,$Ttop,$widthCell,$heightCell,$ligneSup = 0,$ColSup = 0) ;======================================================================================================= ;~ Func InsertSqlite() ;~ $pathData: chemin de la base ;~ $sSql: script SQL à excecuter ;~ $columnView: colonnes visibles de la requête sous forme: "0,2,1,3" la première colonne est 0 ; Note: si le retour de la base exède 50 lignes et 15 colonnes, ; celui-ci est automatiquement aligné sur cette dimension pour des raisons de visibilité ;~ $Handle: Windows handle as returned by GUICreate() ;~ $Tleft: Bord gauche du tableau par rapport au Gui ;~ $Ttop: Sommet du tableau par rapport au Gui ;~ $widthCell: Largeur des cellules ;~ $heightCell: Hauteur des cellules ;~ $ligneSup: (option) lignes suplémentaires dans le bas du tableau ;~ $ColSup: (option) Colonnes suplémentaires à droite du tableau ;Note: si la largeur ou la hauteur du tableau dépasse la fenêtre, ; la largeur ou la hauteur est redimensionnée à la taille de la fenêtre (message d'erreur pour les lignes). ;~ Si la fonction TableSetFormat()n'existe pas ou est créée après cette fonction , le tableau n'est pas construit. ; Func InsertSqlite($pathData,$sSql,$columnView,$Handle,$Tleft,$Ttop,$widthCell,$heightCell,$ligneSup = 0,$ColSup = 0) ToolTip("Recherche des données",250,250,"SQLite") If Not FileExists($pathData) Then Return SetError(1,0,2) If $sSql = "" Then Return SetError(1,0,2) If $columnView = "" Then Return SetError(1,0,2) Local $aResult, $iRows, $iColumns, $iRval _SQLite_Startup() If @error Then MsgBox(0, "SQLite Error", "SQLite.dll Can't be Loaded!") ToolTip("") Return SetError(1,0,1) EndIf _SQLite_Open($pathData) _SQLite_GetTable2d(-1, $sSql, $aResult, $iRows, $iColumns) Local $RowResult = UBound($aResult,1) _SQLite_Close() _SQLite_Shutdown() $sep = StringSplit($columnView,',') If @error Then Return SetError(1,0,2) Local $newArray[UBound($aResult,1)][$sep[0]] If Not IsArray($newArray) Then Return SetError(1,0,2) For $i = 0 To UBound($aResult,1) - 1 For $a = 1 To $sep[0];enregistre les colonnes désignées $newArray[$i][$a - 1] = $aResult[$i][$sep[$a]] Next Next If UBound($newArray,1) > 50 Then ;si plus de 50 lignes >> redimension à 50 $reduit = UBound($newArray,1) - 50 ReDim $newArray[UBound($newArray,1) -$reduit ][UBound($newArray,2)] MsgBox(0,"ERROR","Votre requête retourne " & $RowResult & " lignes" & @CRLF & "Le tableau est redimensionné à 50 lignes",3) EndIf If UBound($newArray,2) > 15 Then; si plus de 15 colonnes >> redimension à 15 $reduit = UBound($newArray,2) - 15 ReDim $newArray[UBound($newArray,1)][UBound($newArray,2) - $reduit] EndIf Local $pos = WinGetPos($Handle) Local $RownewArray = UBound($newArray,1) Local $ColnewArray = UBound($newArray,2) If $RownewArray * $heightCell > $pos[3] - 30 - $Ttop Then;si trop de lignes $heightCell = ($pos[3]- 30 - $Ttop) / $RownewArray;redimensionne la hauteur MsgBox(0,"ERROR","Votre requête retourne " & $RowResult & " lignes" & @CRLF & "La hauteur des lignes dépasse l'interface") EndIf If $ColnewArray * $widthCell > $pos[2] - 8 - $Tleft Then;si trop de colonnes $widthCell = ($pos[2]- 8 - $Tleft) / $ColnewArray ;redimensionne la largeur EndIf InsertArray($newArray,$Handle,$Tleft,$Ttop,$widthCell,$heightCell,$ligneSup ,$ColSup ) ToolTip("") Return $RowResult EndFunc ;InsertSqlite() ;======================================================================================================= ; Func ImportExcel($FilePath,$NSheet,$Range,$Rarray = 0,$Carray = 0,$Visible = 1) ;Description: Importe des données Excel dans un tableau (existant) ; $FilePath: chemin du classeur Excel ; $NSheet: N° de la Feuil e.g. 1 ; $Range: Sélection des données e.g. "A1:F30" ; $Rarray: N° de ligne du tableau Autoit 1 est la première ligne ; $Carray: N° de colonne du tableau Autoit 1 est la première colonne ; $Visible: Feuille Excel 0 = invisible 1 = visible (par défaut) ;Note: Les dimensions du tableau doivent être égales ou supérieurs aux données Excel Func ImportExcel($FilePath,$NSheet,$Range,$Rarray = 1,$Carray = 1,$Visible = 1) If $Rarray < 1 Then $Rarray = 1 If $Carray < 1 Then $Carray = 1 $Rarray = $Rarray - 1 $Carray = $Carray - 1 $Range1 = StringSplit($Range,":") $FirstCell = $Range1[1] ;$LastCell = $Range1[2] Local $oExcel = ObjCreate("Excel.Application") If Not FileExists($FilePath) Then Return SetError(2, 0, 0) If $Visible > 1 Then $Visible = 1 If $Visible < 0 Then $Visible = 0 $oExcel.Visible = $Visible $oExcel.WorkBooks.Open($FilePath) If $NSheet = "" Then $NSheet = 1 If $NSheet > $oExcel.ActiveWorkbook.Sheets.Count Then $NSheet = $oExcel.ActiveWorkbook.Sheets.Count $NbRowsS = $oExcel.Worksheets($NSheet).Range($Range ).Rows.Count $NbColumnsS = $oExcel.Worksheets($NSheet).Range($Range ).Columns.Count $control = 0 If $NbRowsS > UBound($array,1) - $Rarray Then $control = 1 If $NbColumnsS > UBound($array,2) - $Carray Then $control = 1 If $control = 1 Then MsgBox(0,"Error","Les dimensions excèdent le tableau") Else $PrimRow = $oExcel.Worksheets($NSheet).Range($FirstCell).Row $PrimColumn = $oExcel.Worksheets($NSheet).Range($FirstCell).Column $mem = "" $Ni = 0 For $Evalue In $oExcel.Worksheets($NSheet).Range($Range) $ligne = $Evalue.Row - $PrimRow + $Rarray If $mem <> $ligne Then $Ni = 0;$mem est la ligne de travail Si la ligne change, le décalage de colonne $Ni est remis à 0 $colonne = $Evalue.Column - $PrimColumn + $Carray + $Ni For $colonne = $colonne To UBound($array,2) - 1;Si $array[][] vide (fusion par ex.) se place sur colonne suivante $mem = $ligne ;enregistre la ligne courante If $array[$ligne][$colonne] > "" Then;Si valeur existe >> écriture >> sortie de boucle GUICtrlSetData($array[$ligne][$colonne] , $Evalue.Value) ExitLoop EndIf $Ni += 1;compte le décalage de colonne Next Next EndIf $oExcel.ActiveWorkbook.Saved = True $oExcel.Application.Quit EndFunc ;ImportExcel($FilePath,$NSheet,$Range,$Rarray = 1,$Carray = 1,$Visible = 1) ;====================================================================================================== ;~ Func ExportArray( $nomExport, $arrayVisible = 1) ; Description: exporte le tableau dans un array ;~ $nomExport: Nom de l'array sous forme $myArray ;~ $arrayVisible: 1 = $nomExport visible (par défaut) 0 = $nomExport non visible ;Note: $nomExport est redimensionné en fonction des fusions des cellules Func ExportArray(ByRef $nomExport, $arrayVisible = 1) If Not IsArray($array) Then Return SetError(1,0,0) If $array[0][0] = "" Then Return SetError(1,0,0);$array existe mais vide Local $Export [UBound($array,1)][UBound($array,2)] $colAsup = "" $k2 = 0 For $k = 0 To UBound($array,2) - 1 $mavalarray = "" For $l = 0 To UBound($array,1) - 1 If $array[$l][$k] <> "" Then $maval = GUICtrlRead($array[$l][$k]) Else $maval = "" EndIf $mavalarray &= $array[$l][$k] $Export[$l][$k2] = $maval;valeur positionnée sur $K2 Next $k2 = $k2 + 1 If $mavalarray = "" Then;si colonne vide(inexistantes) $colAsup += 1; = nb colonnes vides $k2 = $k2 - 1;décale vers gauche EndIf Next If $colAsup > 0 Then ReDim $Export [UBound($array,1)][UBound($array,2) - $colAsup];supprime colonnes vides (à droite) $nomExport = $Export If $arrayVisible = 1 Then _ArrayDisplay($nomExport,"Export") EndFunc ;ExportArray( $nomExport,$arrayVisible = 1) ;===================================================================================================== ;~ Func ExportBitmapToWord($handle,$WordPath = "",$WordSet = "",$imgLarge=0,$imgHaut=0) ;Description: Exporte l'image du tableau dans un document Word ;~ $Handle: Windows handle as returned by GUICreate() ;~ $WordPath: Chemin d'un document Word Si omis, un nouveau document sera créé ;~ $WordSet: Emplacement du tableau dans Word, 4 possibilités: ; soit omis --> à la fin, soit "start" --> au début, soit "end" --> à la fin, soit un nombre --> se place sous le N° du paragraphe ; Rmq: si le nombre dépasse le nombre de paragraphe, se place à la fin du document ;~ $imgLarge: (option) Redimensionne l'image en largeur ;~ $imgHaut: (option) Redimensionne l'image en hauteur Func ExportBitmapToWord($handle,$WordPath = "",$WordSet = "",$imgLarge=0,$imgHaut=0) If Not IsArray($array) Then Return SetError(1,0,0) If $array[0][0] = "" Then Return SetError(1,0,0);$array existe mais vide $ID1 = $array[0][0] $posForm = WinGetPos($handle,"") $posH = ControlGetPos($handle,"","[CLASS:Edit; ID:" & $ID1 & "]");position haute For $d = UBound($array,2) - 1 To 0 Step -1 $ID2 = $array[UBound($array,1) - 1][$d] If $ID2 > "" Then ExitLoop;si fusion cherche dernière valeur ID dans la dernière ligne Next $posB = ControlGetPos($handle,"","[CLASS:Edit; ID:" & $ID2 & "]");position basse $left = $posForm[0] + $posH[0] + 4;4 et 24 sont les marges du gui $top = $posForm[1] + $posH[1] + 24 $right = $posForm[0] + $posB[0] + $posB[2] + 4 $bottom = $posForm[1] + $posB[1] + $posB[3] + 24 _ScreenCapture_Capture(@TempDir & "\capture_Image1.jpg",$left,$top, _ $right,$bottom,False) If $imgLarge > 0 And $imgHaut > 0 Then ;option redimensions _GDIPlus_StartUp() $hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\capture_Image1.jpg") $hImage2 = _GDIPlus_ImageResize($hImage,$imgLarge,$imgHaut) _GDIPlus_ImageSaveToFile($hImage2, @TempDir & "\capture_Image2.jpg") ; Clean up resources _GDIPlus_ImageDispose($hImage) _GDIPlus_ShutDown() $image = @TempDir & "\capture_Image2.jpg";image redimensionnée Else $image = @TempDir & "\capture_Image1.jpg";image d'origine EndIf $word = ObjCreate("Word.Application") If Not IsObj($word) Then Return SetError(1, 0, 0) $word.visible = True If $WordPath = "" Then $word.Documents.Add;pas de chemin >> nouveau doc If $WordPath > "" Then;chemin >> ouverture If Not FileExists($WordPath) Then Return SetError(2, 0, 0) Local $oword = $word.Documents.Open($WordPath, False, False, False) EndIf If IsNumber($WordSet) Then;Si nombre supérieur aux paragraphes If $WordSet > $word.ActiveDocument.Paragraphs.Count Then $WordSet = $word.ActiveDocument.Paragraphs.Count EndIf Select ;lecture de $WordSet Case $WordSet = "end" $word.ActiveDocument.Paragraphs.Add $word.ActiveDocument.Paragraphs.Last.Range.Select Case $WordSet = "start" $word.ActiveDocument.Paragraphs(1).Range.InsertParagraphBefore $word.ActiveDocument.Paragraphs.First.Range.Select Case IsNumber($WordSet) $word.ActiveDocument.Paragraphs($WordSet).Range.InsertParagraphAfter $word.ActiveDocument.Paragraphs($WordSet + 1).Range.Select Case $WordSet = "" $word.ActiveDocument.Paragraphs.Add $word.ActiveDocument.Paragraphs.Last.Range.Select Case Else MsgBox(0,"Error","Valeur non conforme pour le document Word") Return SetError(1, 0, 0) EndSelect ;~ place le tableau à la sélection $wordopen = $word.ActiveDocument $bb = $word.Selection.Range $Table = $word.ActiveDocument.Tables.Add ($bb, 1, 1, 1, 1) $nbTables = $word.ActiveDocument.Tables.Count $Table.Tables($nbTables).Columns(1).Select $word.Selection.Tables(1).Rows.Alignment = 1 $word.Selection.InlineShapes.AddPicture($image) $nbShapes = $word.ActiveDocument.InlineShapes.Count $word.ActiveDocument.InlineShapes.Item($nbShapes).LockAspectRatio = -1 $Table.AutoFormat(0,False,False,False,False,False,False,False,False,True) FileDelete(@TempDir & "\capture_Image1.jpg") FileDelete(@TempDir & "\capture_Image2.jpg") EndFunc ;ExportBitmapToWord($WordPath = "",$WordSet = "") ;===================================================================================================== ;~ Func ExportWord($WordPath = "",$WordSet = "", $BordersOutside = 1, $BordersInside = 1) ;Description: Exporte le tableau dans un document Word ;~ $WordPath: Chemin d'un document Word Si omis, un nouveau document sera créé ;~ $WordSet: Emplacement du tableau dans Word, 4 possibilités: ; soit omis --> à la fin, soit "start" --> au début, soit "end" --> à la fin, soit un nombre --> se place sous le N° du paragraphe ; Rmq: si le nombre dépasse le nombre de paragraphe, se place à la fin du document ;~ $BordersOutside: 1 = Bordures extérieurs du tableau visible, 0 = non visible, par défaut 1 ;~ $BordersInside: 1 = Bordures intérieurs du tableau visible, 0 = non visible, par défaut 1 ;~ Note: Les fusions de cellules sont répercutées sur le tableau Word Func ExportWord($WordPath = "",$WordSet = "", $BordersOutside = 1, $BordersInside = 1) ;Const $wdCharacter = 1 ;Const $wdExtend = 1 ;Const $wdLineStyleSingle = 1 If Not IsArray($array) Then Return SetError(1,0,0) If $array[0][0] = "" Then Return SetError(1,0,0);$array existe mais vide Local $Wexport [UBound($array,1)][UBound($array,2)] For $k = 0 To UBound($array,2) - 1 For $l = 0 To UBound($array,1) - 1 If $array[$l][$k] <> "" Then ;lecture du $array des ID $maval = GUICtrlRead($array[$l][$k]) ;Si ID >> lecture tableau Else $maval = "" ;Non ID >> pas de lecture EndIf $Wexport[$l][$k] = $maval Next Next $word = ObjCreate("Word.Application") If Not IsObj($word) Then Return SetError(1, 0, 0) $word.visible = True If $WordPath = "" Then $word.Documents.Add;pas de chemin >> nouveau doc If $WordPath > "" Then;chemin >> ouverture If Not FileExists($WordPath) Then Return SetError(2, 0, 0) Local $oword = $word.Documents.Open($WordPath, False, False, False) EndIf If IsNumber($WordSet) Then;Si nombre supérieur aux paragraphes If $WordSet > $word.ActiveDocument.Paragraphs.Count Then $WordSet = $word.ActiveDocument.Paragraphs.Count EndIf Select ;lecture de $WordSet Case $WordSet = "end" $word.ActiveDocument.Paragraphs.Add $word.ActiveDocument.Paragraphs.Last.Range.Select Case $WordSet = "start" $word.ActiveDocument.Paragraphs(1).Range.InsertParagraphBefore $word.ActiveDocument.Paragraphs.First.Range.Select Case IsNumber($WordSet) $word.ActiveDocument.Paragraphs($WordSet).Range.InsertParagraphAfter $word.ActiveDocument.Paragraphs($WordSet + 1).Range.Select Case $WordSet = "" $word.ActiveDocument.Paragraphs.Add $word.ActiveDocument.Paragraphs.Last.Range.Select Case Else MsgBox(0,"Error","Valeur non conforme pour le document Word") Return SetError(1, 0, 0) EndSelect ;~ place le tableau à la sélection $wordopen = $word.ActiveDocument $bb = $word.Selection.Range $matable = $wordopen.Tables.Add($bb, UBound($Wexport,1), UBound($Wexport,2),Default,Default) If $BordersInside = 1 Then $matable.Borders.InsideLineStyle = 1;$wdLineStyleSingle If $BordersOutside = 1 Then $matable.Borders.OutsideLineStyle = 1;$wdLineStyleSingle For $i = 1 To UBound($Wexport,1) For $y = 1 To UBound($Wexport,2);lecture écriture du array $matable.Cell($i,$y).Range.InsertAfter ($Wexport[$i - 1][$y - 1]) Next $TTT = $matable.Rows($i).Cells.Count For $y = 1 To $TTT;fusion des cellules $matable.Cell($i, $y).Select If StringLeft($word.Selection.Text,6) = "" Then $word.Selection.Text = "";efface $matable.Cell($i, $y).Previous.Select;sélectionne la cell avant $word.Selection.MoveRight (1, 1, 1);étend la sélection à 2 cells $word.Selection.MoveRight($wdCharacter, 1, $wdExtend) $word.Selection.Cells.Merge;fusion $y = $y - 1;si fusion une cell de moins, on revient en arrière EndIf Next Next EndFunc ;Func ExportWord($WordPath = "",$WordSet = "", $BordersOutside = 1, $BordersInside = 1) ;~ ======================================================================================================= ;~ Func AutoFormule($iRow,$iColumn,$iFormul) ;~ Description: Entre automatiquement dans le tableau, une formule ;~ $iRow: La ligne concernée 1 étant première ;~ $iColumn: la colonne concernée 1 étant première ;~ $iFormul: la formule à appliquer entre guillemets ; Syntaxe de formule: e.g. "=<1,1>+<4,1>" "=<1,1>*0.196" "=Automatique" Voir Func formule Func AutoFormule($iRow,$iColumn,$iFormul) If Not IsArray($array) Then Return SetError(1,0,0) If $iRow = "" Or $iColumn = "" Or $iFormul = "" Then Return SetError(1,0,1) If $iRow > UBound($array,1) Or $iColumn > UBound($array,2) Then Return SetError(2,0,2) If StringLeft($iFormul,1) = '=' Then GUICtrlSetData($array[$iRow - 1 ][$iColumn - 1],$iFormul) $repond = GUICtrlRead($array[$iRow - 1 ][$iColumn - 1]) $nMsg = $array[$iRow - 1 ][$iColumn - 1] formule($roundFmsg) EndIf EndFunc ;AutoFormule($iRow,$iColumn,$iFormul) ;========================================================================================================= ;~ Func AutoStyle($yRow,$yColumn,$ySize = '',$yWeight = '',$yAttribut = '',$yFontname = '',$yStyle = '') ; Description; Formate une cellule indépendamment de TableSetFormat() ;~ $yRow: La ligne concernée 1 étant première ;~ $yColumn: la colonne concernée 1 étant première ;~ $ySize: Fontsize >>>> Voir GUICtrlSetFont() ;~ $yWeight: The weight of the font ;~ $yAttribut: Font attributes ;~ $yFontname: Name of the font to use. ;~ $yStyle: Defines the style of the control. >>>> Voir GUICtrlSetStyle() ;~Rmq: Les styles à utiliser sont $ES_CENTER, $ES_LOWERCASE, $ES_RIGHT, $ES_UPPERCASE Func AutoStyle($yRow,$yColumn,$ySize = '',$yWeight = '',$yAttribut = '',$yFontname = '',$yStyle = '') If Not IsArray($array) Then Return SetError(1,0,0) If $yRow = "" Or $yColumn = "" Then Return SetError(1,0,1) If $yRow > UBound($array,1) Or $yColumn > UBound($array,2) Then Return SetError(1,0,2) GUICtrlSetFont($array[$yRow - 1 ][$yColumn - 1],$ySize,$yWeight,$yAttribut,$yFontname) GUICtrlSetStyle($array[$yRow - 1 ][$yColumn - 1],$yStyle) EndFunc ;AutoStyle($yRow,$yColumn,$ySize = '',$yWeight = '',$yAttribut = '',$yFontname = '',$yStyle = '') ;================================================================================================ ;~ Func IncrementeFormuleV($Cformul,$Formul,$Rdepart,$Cdepart,$Rfin,$Cfin) ;~ Syntaxe: e.g. IncrementeFormuleV(10,"SUM",1,2,10,5) ;~ Incrémente une formule verticalement dans le tableau ;Soit ,Somme par ligne des valeurs comprises entre la ligne 1 colonne 2 et la ligne 10 colonne 5 Les 10 résultats correspants dans la colonne 10 ;~ $Cformul: colonne des résultats ;~ $Formul : Formule soit "SUM", soit "MOY", soit "MIN", soit "MAX" pour Somme, Moyenne, Maximum, Minimum ;~ $Formul peut avoir aussi un des signes + - * / (plus, moins etc..) Dans ce cas, seules deux valeurs par ligne dans les colonnes $Cdepart et $Cfin ;~ seront calculées entre les lignes $Rdepart et $Rfin ;~ $Rdepart: Première ligne des données à calculer (équivaut pour Excel à Cells(1, ) e.g. Range(Cells(1,2),Cells(10,5)) ) ;~ $Cdepart: Première colonne des données à calculer (équivaut à Cells( ,2)) ;~ $Rfin: Dernière ligne des données à calculer (équivaut à Cells(10, )) ;~ $Cfin: Dernière colonne des données à calculer (équivaut à Cells( ,5 )) ;Note: En l'absence de valeurs numériques, le signe "/" retourne une erreur qui disparait à l'ajout des nombres Func IncrementeFormuleV($Cformul,$Formul,$Rdepart,$Cdepart,$Rfin,$Cfin) If Not IsArray($array) Then Return SetError(1,0,0) If $Cformul = "" Or $Formul = "" Or $Rdepart = "" Or $Cdepart = "" Or $Rfin = "" Or $Cfin = "" Then Return SetError(1,0,0) If $Cformul > UBound($array,2) Or $Cdepart > UBound($array,2) Or $Cfin > UBound($array,2) Then Return SetError(1,0,0) If $Rdepart > UBound($array,1) Or $Rfin > UBound($array,1) Then Return SetError(1,0,0) For $i = $Rdepart To $Rfin Select Case $Formul = "SUM" Or $Formul = "MOY" Or $Formul = "MIN" Or $Formul = "MAX" GUICtrlSetData($array[$i - 1 ][$Cformul - 1],"=" & $Formul & "<" & $i & "," & $Cdepart & "><" & $i & "," & $Cfin & ">") $repond = GUICtrlRead($array[$i - 1 ][$Cformul - 1]) $nMsg = $array[$i - 1 ][$Cformul - 1] Formule($roundFmsg) Case $Formul = "+" Or $Formul = "-" Or $Formul = "/" Or $Formul = "*" GUICtrlSetData($array[$i - 1 ][$Cformul - 1],"=<" & $i & "," & $Cdepart & ">"& $Formul & "<" & $i & "," & $Cfin & ">") $repond = GUICtrlRead($array[$i - 1 ][$Cformul - 1]) $nMsg = $array[$i - 1 ][$Cformul - 1] Formule($roundFmsg) ;MsgBox(0,"","arrondi") EndSelect Next EndFunc ;IncrementeFormuleV($Cformul,$Formul,$Rdepart,$Cdepart,$Rfin,$Cfin) ;~ ===================================================================================================== ;~ Func ValeurRetour($ligneVR,$columnVR,$columnRetour = "",$Condition = "") ;Description: La Fonction retourne la valeur d'une cellule avec ou sans condition ;~ $ligneVR: ligne où se trouve la cellule à surveiller, 1 étant la première ;~ $columnVR: colonne où se trouve la cellule à surveiller, 1 étant la première ;~ $columnRetour: colonne à désigner pour un retour de valeur autre que la cellule à surveiller (optionnel) ;~ $Condition: (option)la cellule à surveiller répond à un critère ">valeur" "=valeur" "<=valeur" valeur étant un nombre ;~ note:La fonction peut se combiner e.g.$aa = ValeurRetour(1,2) MsgBox(0,"",ValeurRetour(1,1,"",">" & $aa)) ;~ Msgbox affichera la cellule 1 si celle-ci est supérieur à la cellule 2 ($aa) Func ValeurRetour($ligneVR,$columnVR,$columnRetour = "",$Condition = "") Global $valeurRetour = "" If Not IsArray($array) Then Return SetError(1,0,0) If $ligneVR = "" Or $columnVR = "" Then Return SetError(1,0,1) If $ligneVR > UBound($array,1) Or $columnVR > UBound($array,2) Or $columnRetour > UBound($array,2) Then Return SetError(2,0,1) $valeur = GUICtrlRead($array[$ligneVR - 1][$columnVR - 1]) If $columnRetour > "" Then $valeurR = GUICtrlRead($array[$ligneVR - 1][$columnRetour - 1]) If $Condition > "" And $columnRetour > "" Then $retour = Execute($valeur & $Condition) If $retour = True Then $valeurRetour = $valeurR EndIf If $Condition > "" And $columnRetour = "" Then $retour = Execute($valeur & $Condition) If $retour = True Then $valeurRetour = $valeur EndIf If $Condition = "" And $columnRetour > "" Then $valeurRetour = $valeurR EndIf If $Condition = "" And $columnRetour = "" Then $valeurRetour = $valeur EndIf Return $valeurRetour EndFunc ;ValeurRetour($ligneVR,$columnVR,$columnRetour = "",$Condition = "") ;~ Fonction interne =============================================================================== ;~ Func formule($roundFmsg = 2) ; Description: Effectue les calculs du tableau en fonction des formules utilisées commencant par = ; Pour désigner une cellule soit Row, Column, le premier élément est 1 e.g. <1,1>. Les signes sont les signes mathématiques ; E.g. Calcul simple: = 2 + 3, référence à une cellule: = <4,2> + 3, référence à plusieurs cellules: =<4,2>+<5,3> ; Somme ou moyenne entre deux cellules par ligne ou colonne: Somme: =SUM<4,1><4,10>. Moyenne: = MOY<2,1><4,1> ; Concaténer des valeurs numériques ou alphanumériques: =<1,2><3,5><7,7> ;~ $roundFmsg: (option) Nombre de décimals aprés la virgule, par Default 2 ; Note: Les formules sont enregistrées et recalculées à chaque modification du tableau ; si MsgArray($nMsg ) a été utilisé Func formule($roundFmsg = 2) If Not IsArray($array) Then Return SetError(1,0,0) Global $cumul = "", $Maxi, $Mini, $key,$maxmin, $Rval GUICtrlSetBkColor($nMsg,0xFFFFFF);efface couleur sur Handle $repond = StringStripWS($repond,8) ;supprime les espaces vides $index = _ArraySearch($myarray,$nMsg,0,0,0,0,1,0);recherche formule existante pour détruire If $index >= 0 Then _ArrayDelete($myarray,$index) If StringLeft($repond,1) = "=" Then ;Si formule If StringMid($repond,2,4) = "SUM<" Then Somme() $repond = $cumul EndIf If StringMid($repond,2,4) = "MOY<" Then Moyenne() $repond = $cumul EndIf If StringMid($repond,2,4) = "MAX<" Then $key = "maxi" MaxiMini() $repond = $maxmin EndIf If StringMid($repond,2,4) = "MIN<" Then $key = "mini" MaxiMini() $repond = $maxmin EndIf If StringRight($repond,1) <> ">" Then;permet expression comme <4,2>*3 $repond = $repond & "<>" EndIf ;extraire données entre < R,C > et > +-*/ < $aArray1 = StringRegExp($repond, '(?i)<(.*?)>', 3);référence à cell $aArray2 = StringRegExp($repond, '(?i)>(.*?)<', 3);référence à une opération If Not IsArray($aArray2) Then Local $aArray2[1] $x = 1 For $W = 0 To UBound($aArray2) - 1;écriture des données de la cell L1: 4,2 L2: +3+ L3: 4,3 L4: + etc... _ArrayInsert($aArray1,$x,$aArray2[$W]) $x = $x + 2 Next $redim = UBound($aArray1) $nbcolumn = $redim - UBound($myarray,2) + 1 If $nbcolumn < 0 Then $nbcolumn = 0 ;redimensionne $myarray selon $aArray1 et écriture des données >> $myarray contient le handle et la formule découpée en colonne ReDim $myarray[UBound($myarray,1) + 1][UBound($myarray,2) + $nbcolumn] For $i = 0 To UBound($myarray,2) - 1 If $i = 0 Then $myarray[UBound($myarray,1)-1][$i] = $nMsg;colonne 0 >> le handle Else If $i <= UBound($aArray1) Then $myarray[UBound($myarray,1)-1][$i] = $aArray1[$i - 1] EndIf Next EndIf calcul($roundFmsg) _ArraySort($myarray, 0, 0, 0, 0) calcul($roundFmsg) _ArraySort($myarray, 1, 0, 0, 0) calcul($roundFmsg) ;_ArrayDisplay($myarray,"formule") _ArraySort($myarray, 0, 0, 0, 0) calcul($roundFmsg) ;calcul 4 fois >> problème formules en cascade EndFunc ;formule() ;~ Fonction interne =================================================================== Func calcul($round = 2) For $i = 0 To UBound($myarray,1) - 1 $valCellT = "" For $y = 1 To UBound($myarray,2) - 1;se positionne sur la 2 colonne ;_ArrayDisplay($myarray) If $myarray[$i][1] = "" Then ExitLoop ;Si colonne 2 vide, on sort If $myarray[$i][2] = "mini" Or $myarray[$i][2] = "maxi" Then $val1 = $myarray[$i][1] $val2 = $myarray[$i][3] $key = $myarray[$i][2] MaxiMini($val1,$val2) $valCellT = $Rval ;ConsoleWrite($i & ">>" & $y &">val"& $valCellT & @CRLF) ExitLoop EndIf If $y = 3 And $myarray[$i][3] = "" Then ExitLoop ;Si colonne 4 vide, on sort If $y = 4 And $myarray[$i][4] = "" Then ExitLoop $cell = StringSplit($myarray[$i][$y],",") If Not @error Then ; Split possible la forme est de type 4,2 >> lecture ligne/colonne ;gestion des erreurs de saisie (hors dimension) If $cell[1] > UBound($array,1) Or $cell[1] < 1 Then Return SetError(0,1,1);ligne n'existe pas If $cell[2] > UBound($array,2) Or $cell[2] < 1 Then Return SetError(0,1,1);colonne n'existe pas If $array[$cell[1] - 1][$cell[2] - 1] = "" Then Return SetError(0,1,1) ;cell n'existe pas suite à fusion $valCell = GUICtrlRead($array[$cell[1] - 1][$cell[2] - 1]) If $valCell = "" Then $valCell = 0 $valCellT &= $valCell ;lecture des données converties en valeur ;ConsoleWrite($i & ">>" & $y &">val> "& $valCellT & @CRLF) Else ;split impossible correspond à une opération e.g. +4+ $valCell = $myarray[$i][$y] $valCellT &= $valCell ;ConsoleWrite($i & ">>" & $y &">sign< "& $valCellT & @CRLF) EndIf Next $hand = $myarray[$i][0] If $myarray[$i][1] = "" Then;si colonne 2 vide >> format de type =3+2 $calculsimple = GUICtrlRead($hand) $calculsimple = StringReplace($calculsimple,"=","") $result = Execute($calculsimple) If $result > "" Then $result = StringFormat("%." & $round & "f",$result);Round($result,$round) GUICtrlSetData($hand,$result) EndIf If $result = "" Then GUICtrlSetData($hand,$calculsimple) GUICtrlSetBkColor($hand,0xFFCCFF) Else ;si colonne 2 = valeur >> format de type =<4,2>+<4,1> convertit en 12+5 $result = Execute($valCellT) ;Calcul la valeur If @error Then; $result n'est pas numérique GUICtrlSetData($hand,$valCellT) Else ;$result est numérique $result = StringFormat("%." & $round & "f",$result);Round($result,$round) GUICtrlSetData($hand,$result) EndIf GUICtrlSetBkColor($hand,0xFFCCFF) EndIf Next EndFunc ;calcul() ;~ Fonction interne ======================================================================== Func Somme() $aArray1 = StringRegExp($repond, '(?i)<(.*?)>', 3);référence à cell ;_ArrayDisplay($aArray1) $split0 = StringSplit($aArray1[0],",") $split1 = StringSplit($aArray1[1],",") If @error Then Return SetError(0,0,1) ;_ArrayDisplay($split1) If $split0[1] = $split1[1] Or $split0[2] =$split1[2] Then If $split0[1] = $split1[1] Then ;même ligne For $p = 0 To $split1[2] - $split0[2] If $array[$split0[1] - 1][$split0[2 ] + $p - 1] <> "" Then ;vérifie que le handle existe (fusion) If $p = $split1[2] - $split0[2] Then $cumul &="<" & $split0[1] & "," & $split0[2 ] + $p & ">" Else $cumul &="<" & $split0[1] & "," & $split0[2 ] + $p & "> +" EndIf EndIf Next Else ;même colonne For $p = 0 To $split1[1] - $split0[1] If $array[$split0[1] + $p - 1][$split0[2 ] - 1] <> "" Then ;vérifie que le handle existe (fusion) If $p = $split1[1] - $split0[1] Then $cumul &="<" & $split0[1] + $p & "," & $split0[2 ] & ">" Else $cumul &="<" & $split0[1] + $p & "," & $split0[2 ] & "> +" EndIf EndIf ;_ArrayDisplay($split1) Next EndIf Else MsgBox(0,"Error","Le calcul doit être sur une même ligne ou une même colonne") $repond = "<>" EndIf EndFunc ;Somme() ;~ Fonction interne ======================================================================== Func Moyenne() Somme() $aArray1 = StringRegExp($cumul, '(?i)<(.*?)>', 3);référence à cell $divise = UBound($aArray1) $cumul = "<(>" & $cumul & ")/" & $divise EndFunc ;Moyenne() ;~ Fonction interne ======================================================================== ;~ Func MaxiMini() Func MaxiMini($val1 = "",$val2 = "") If $val1 = "" Then Local $aArray1 = StringRegExp($repond, '(?i)<(.*?)>', 3);référence à cell Else Local $aArray1[2] = [$val1,$val2];format R,C|R,C EndIf $split0 = StringSplit($aArray1[0],",") $split1 = StringSplit($aArray1[1],",") $nbcellsA = ($split1[1] - $split0[1] + 1)* ($split1[2] - $split0[2] + 1);calcul nb cells Local $ArrayMaxMin[$nbcellsA] If Not IsArray($ArrayMaxMin) Then SetError(2,0,0) $A = 0 For $i = $split0[1] To $split1[1] For $y = $split0[2] To $split1[2] $valmaxmin = GUICtrlRead($array[$i - 1][$y - 1]) If $valmaxmin = "" Then ReDim $ArrayMaxMin[UBound($ArrayMaxMin) - 1] Else ;convertit la valeur en Number() sinon bug dans _ArraySort If Number($valmaxmin)<> 0 Then $valmaxmin = Number($valmaxmin) $ArrayMaxMin[$A] = $valmaxmin $A += 1 EndIf Next Next If $A = 0 Then Return SetError(2,0,0) ;pas de valeurs trouvées _ArraySort($ArrayMaxMin);,0,0,0,0,1) ;_ArrayDisplay($ArrayMaxMin) If $key = "maxi" Then $Rval = $ArrayMaxMin[UBound($ArrayMaxMin) - 1] If $key = "mini" Then $Rval = $ArrayMaxMin[0] $maxmin = "<" & $aArray1[0] & ">" & $key & "<" & $aArray1[1] & ">" EndFunc;MaxiMini()