voici un petit udf pour gérer les tableaux 2D :
Voici le code de _Array2D.au3
Code : Tout sélectionner
#include-Once
; #INDEX# =======================================================================================================================
; Title .........: _Array2D
; AutoIt Version : 3.3.6.1 (tested on this version)
; Language ......: English
; Description ...: Functions for manipulating array 2D
; Author(s) .....: Ricky with a part of code from array.au3
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
;_ArrayAdd2D
;_ArrayConcatenate2D
;_Array2DToHtml
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name...........: _ArrayConcatenate2D
; Version........: 1.1
; Last Modified..: 09.05.2011
; Description ...: Concatenate two arrays 2D.
; Syntax.........: _ArrayConcatenate(ByRef $Target, $Source, $Row0Update = 0)
; Parameters ....: $Target - The array 2D to concatenate onto
; $Source - The array 2D to concatenate from
; $Row0Update - 0 (default) do nothing
; - 1 update the number of lignes in $Target[0][0]
; Return values .: Success - $Target's new size
; Failure - 0, sets @error to:
; |1 - $Target is not an array
; |2 - $Source is not an array
; |3 - $Target is not a 2 dimensional array
; |4 - $Source is not a 2 dimensional array
; |5 - $Target and $Source is not a 2 dimensional array
; |6 - The cols of the source aren't the same as the target
; |7 - $Target[0][0] is not a number
; Author ........: Ricky
; Modified.......: Partypooper - added target start index
; Remarks .......: Based on _ArrayConcatenate from Ultima
; Related .......:
; Link ..........: http://www.autoitscript.fr/forum/viewtopic.php?f=21&t=7413
; Example .......: Yes
; ===============================================================================================================================
Func _ArrayConcatenate2D(Byref $Target, $Source, $Row0Update = 0)
If Not IsArray($Target) Then Return SetError(1, 0, 0)
If Not IsArray($Source) Then Return SetError(2, 0, 0)
If UBound($Target, 0) <> 2 Then
If UBound($Source, 0) <> 2 Then Return SetError(5, 0, 0)
Return SetError(3, 0, 0)
EndIf
If UBound($Source, 0) <> 2 Then Return SetError(4, 0, 0)
Local $rowsTarget = UBound($Target)
Local $colsTarget = UBound($Target, 2)
Local $rowsSource = UBound($Source)
Local $colsSource = UBound($Source, 2)
if $colsTarget <> $colsSource then Return SetError(6, 0, 0)
$newRowsSize = $rowsTarget+$rowsSource
if $Row0Update = 1 then
If NOT IsNumber($Target[0][0]) Then Return SetError(7, 0, 0)
$Target[0][0] = $newRowsSize - 1
EndIf
Redim $Target[$newRowsSize][$colsTarget]
for $i=$rowsTarget to $newRowsSize - 1
for $j = 0 to $colsTarget - 1
$Target[$i][$j] = $Source[$i-$rowsSource][$j]
Next
Next
Return $newRowsSize
EndFunc
; #FUNCTION# ====================================================================================================================
; Name...........: _ArrayAdd2D
; Version........: 1.1
; Last Modified..: 09.05.2011
; Description ...: Adds an array 1D at the end of an existing array2D.
; Syntax.........: _ArrayAdd(ByRef $Target, $Source, $Row0Update = 0)
; Parameters ....: $Target - Array to modify
; $vValue - Array to add
; $Row0Update - 0 (default) do nothing
; - 1 update the number of lignes in $Target[0][0]
; Return values .: Success - Index of last added item
; Failure - 0, sets @error
; |1 - $Target is not an array
; |2 - $Source is not an array
; |3 - $Target is not a 2 dimensional array
; |4 - $Source is not a 1 dimensional array
; |5 - The rows of the source aren't in the same size of the cols of the target
; |6 - $Target[0][0] is not a number
; Author ........: Ricky
; Modified.......:
; Remarks .......: Based on _ArrayAdd from Jos van der Zande <jdeb at autoitscript dot com>
; Related .......:
; Link ..........: http://www.autoitscript.fr/forum/viewtopic.php?f=21&t=7413
; Example .......: Yes
; ===============================================================================================================================
Func _ArrayAdd2D(ByRef $Target, $Source, $Row0Update = 0)
If Not IsArray($Target) Then Return SetError(1, 0, 0)
If Not IsArray($Source) Then Return SetError(2, 0, 0)
If UBound($Target, 0) <> 2 Then Return SetError(3, 0, 0)
If UBound($Source, 0) <> 1 Then Return SetError(4, 0, 0)
Local $rowsSource = UBound($Source)
Local $colsTarget = UBound($Target, 2)
if $rowsSource <> $colsTarget Then Return SetError(5, 0, 0)
Local $iUBound = UBound($Target)
if $Row0Update = 1 then
If NOT IsNumber($Target[0][0]) Then Return SetError(6, 0, 0)
$Target[0][0] = $iUBound
EndIf
ReDim $Target[$iUBound + 1][$colsTarget]
For $i=0 to $colsTarget - 1
$Target[$iUBound][$i] = $Source[$i]
Next
Return $iUBound
EndFunc ;==>_ArrayAdd
; #FUNCTION# ====================================================================================================================
; Name...........: _Array2DToHtml
; Version........: 1.1
; Last Modified..: 03.05.2011
; Description ...: Write an 2D array in a html FILE
; Syntax.........: _Array2DToHtml($sArray, $FileName, $Title, $row0Names = 0)
; Parameters ....: $sArray - Array with the values
; $FileName - File name with the path and the extension (if a file exists, the oldest is deleted)
; $Title - Title of the file
; $row0Names - 0 (default) the name of the cols aren't present
; - 1 the name of the cols are present in the row 0
; Return values .: Success - 1
; Failure - 0 if file not opened in writemode, file is read only, or file cannot otherwise be written to.
; Author ........: Ricky
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://www.autoitscript.fr/forum/viewtopic.php?f=21&t=7413
; Example .......: Yes
; ===============================================================================================================================
Func _Array2DToHtml($sArray, $FileName, $Title, $row0Names = 0)
$rows = UBound($sArray) - 1 ; nombre de lignes
$cols = UBound($sArray, 2) - 1 ; nombre de colonnes
$Output = ''
$Output &= '<html>' & @CRLF & '<head>' & @CRLF
$Output &= '<meta name="generator" content="AutoIT Array2DToHtml"/>' & @CRLF
$Output &= '<meta name="author" content="Ricky"/>' & @CRLF
$Output &= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' & @CRLF & '<style type="text/css">' & @CRLF
$Output &= 'table {border: solid #808080; border-top-width:1; border-left-width:0; border-bottom-width:0; border-right-width:1;}' & @CRLF
if $row0Names = 1 then $Output &= 'th {background-color: #0080C0; color: #FFFFFF; border: solid #808080; border-top-width:0; border-left-width:1; border-bottom-width:1; border-right-width:0;}' & @CRLF
$Output &= 'td {background-color: #FFFFFF; color: #000000; border: solid #808080; border-top-width:0; border-left-width:1; border-bottom-width:1; border-right-width:0;}' & @CRLF
$Output &= 'td.space {background-color: #FFFFFF; color: #000000; border: solid #808080; border-top-width:0; border-left-width:0; border-bottom-width:1; border-right-width:0;}' & @CRLF
$Output &= '</style>' & @CRLF & '</head>' & @CRLF & '<body>' & @CRLF & '<center>' & @CRLF & '<h2>' & $Title & '</h2>' & @CRLF
$Output &= '<table border="0" cellspacing="0" cellpadding="2" width="100%">' & @CRLF
for $i=1 to $rows
$Output &= '<tr>' & @CRLF
if $i = 1 and $row0Names = 1 then
; écriture de la ligne de titre qui est différente
for $j=0 to $cols
$Output &= '<th align="center"><font size="1" face="arial"> ' & $sArray[0][$j] & '</font></th>' & @CRLF
Next
$Output &= '</tr>' & @CRLF & '<tr>' & @CRLF
EndIf
for $j=0 to $cols
$Output &= '<td align="left"><font size="1" face="arial"> ' & $sArray[$i][$j] & '</font></td>' & @CRLF
Next
$Output &= '</tr>' & @CRLF
next
$Output &= '</table>' & @CRLF & '</center>' & @CRLF & '</body>' & @CRLF & '</html>'
if FileExists($FileName) then FileDelete($FileName)
$Result = FileWrite($FileName, $Output )
Return $Result
EndFunc
Code : Tout sélectionner
#include <Array.au3>
#include "_Array2D.au3"
Local $avArrayTarget[5][2]
$avArrayTarget[0][0]=4
$avArrayTarget[1][0]="b"
$avArrayTarget[2][0]="c"
$avArrayTarget[3][0]="d"
$avArrayTarget[4][0]="e"
$avArrayTarget[0][1]="f"
$avArrayTarget[1][1]="g"
$avArrayTarget[2][1]="h"
$avArrayTarget[3][1]="i"
$avArrayTarget[4][1]="j"
Local $avArraySource[5][2]
$avArraySource[0][0]=1
$avArraySource[1][0]=2
$avArraySource[2][0]=3
$avArraySource[3][0]=4
$avArraySource[4][0]=5
$avArraySource[0][1]=6
$avArraySource[1][1]=7
$avArraySource[2][1]=8
$avArraySource[3][1]=9
$avArraySource[4][1]=10
Local $Array1D[2] = ["Ajout","ligne"]
_ArrayDisplay($avArrayTarget, "$avArrayTarget BEFORE _ArrayConcatenate2D()")
if _ArrayConcatenate2D($avArrayTarget, $avArraySource,1) = 0 Then MsgBox(0,"Error", "Message : " & @error)
_ArrayDisplay($avArrayTarget, "$avArrayTarget AFTER _ArrayConcatenate2D()")
if _ArrayAdd2D($avArrayTarget,$Array1D,1) = 0 Then MsgBox(0,"Error", "Message : " & @error)
_ArrayDisplay($avArrayTarget, "$avArrayTarget AFTER _ArrayAdd2D()")
Local $avArray[15][3] = [ _
["Name", "Value", "int"], _
["A", "d", 1], _
["b", "g", 4], _
["z", "f", 12], _
["A", "c", 3], _
["b", "e", 6], _
["z", "e", 13], _
["", "z", 7], _
["z", "a", 14], _
["A", "B", 2], _
["", "t", 8], _
["", "y", 9], _
["b", "f", 5], _
["y", "f", 11], _
["", "A", 10]]
$FileName = @ScriptDir & "\test.html"
$Title = "Test of the function"
Array2DToHtml($avArray, $FileName, $Title, 1)