Code : Tout sélectionner
#include <ArrayEx.au3>
#include <File.au3>
#include <Excel.au3>
Global $TestNom=""
Global $Increm=""
Global $CheckMesure=""
Global $ExcelRowStart = 3, $aArray, $Unity
Global $TableauSortie[0][15]
_FONCTION_TEST()
Func _FONCTION_TEST()
$aArray = _FileListToArray(@ScriptDir&"\Test\", "*", 1)
;_ArrayDisplay($aArray)
Redim $TableauSortie[Ubound($aArray,1)*2][50]
_Arraydisplay($TableauSortie)
Local $oAppl = _Excel_Open()
Global $oWorkbook = _Excel_BookNew($oAppl)
If @error Then
MsgBox(64, "", "Error creating the new workbook.")
_Excel_Close($oAppl)
EndIf
$oWorkbook.sheets("Feuil1").Range("A2").Value = "Nom fichier"
$oWorkbook.sheets("Feuil1").Range("B2").Value = "Point de sertissage"
$oWorkbook.sheets("Feuil1").Range("C2").Value = "Référence"
$oWorkbook.sheets("Feuil1").Range("D2").Value = "Date"
$oWorkbook.sheets("Feuil1").Range("E2").Value = "Heure"
$oWorkbook.ActiveSheet.Range("A2:R2").Font.Bold = True
$oWorkbook.ActiveSheet.Range("G1:R1").Font.Bold = True
For $i = 1 To UBound($aArray) - 1
ConsoleWrite($aArray[$i]&@CRLF)
Global $DummyFile = $aArray[$i]
_ReadFile($DummyFile, $i)
Next
$oWorkbook.ActiveSheet.Columns("A:R").AutoFit
_Arraydisplay($TableauSortie)
_ExcelWrite()
EndFunc
Func _ReadFile($DummyFile, $i)
Local $hFileRead = FileRead(@ScriptDir&"\Test\" & $DummyFile)
;~ Msgbox(1,"test",$hFileRead)
Local $aString2 = _StringToArray2D($hFileRead, @CRLF, ";", 1)
$aString2[0][0] = StringReplace($aString2[0][0], " ", "")
Local $aSplit = StringSplit($aString2[0][0], "'")
Local $aSplitDateTime = StringSplit($aString2[1][0], " ")
Local $iIndex = _ArraySearch($aString2, "")
For $x = UBound($aSplit) - 1 To 0 Step - 1
If $aSplit[$x] Then
Else
_ArrayDelete($aSplit, $x)
EndIf
Next
;~ _ArrayDisplay($aString2)
$TableauSortie[$i-1][1]=$iIndex
$TableauSortie[$i-1][2]= StringReplace($aArray[$i], "'", "")
$TableauSortie[$i-1][3]=$aSplit[1]
$TableauSortie[$i-1][4]=$aSplit[2]
$TableauSortie[$i-1][5]=StringReplace($aSplitDateTime[1], "'", "")
$TableauSortie[$i-1][6]=StringReplace($aSplitDateTime[2], "'", "")
For $a=5 To $iIndex -1
$TableauSortie[$i-1][$a+2]=StringReplace(StringReplace(StringReplace(StringReplace($aString2[$a][0], "'", ""), "=", ""), "nicht auswertbar", ""), " ", "")
$TableauSortie[$i-1][0]&=StringReplace(StringReplace(StringReplace(StringReplace($aString2[$a][0], "'", ""), "=", ""), "nicht auswertbar", ""), " ", "")
If StringInStr($aString2[$a][0], "nicht") Then
$TableauSortie[$i-1][$a+($iIndex-3)] = "n.a"
$TableauSortie[$i-1][$a+($iIndex-3)] = 3
$TableauSortie[$i-1][$a+($iIndex-3)] = True
Else
$TableauSortie[$i-1][$a+($iIndex-3)] = $aString2[$a][1]
EndIf
Next
FileClose($hFileRead)
EndFunc
Func _ExcelWrite()
For $i=1 to UBound($aArray) - 1
If $i>2 Then
If $TableauSortie[$i-1][1]=$TableauSortie[$i-2][1] Then
$ExcelRowStart+=1
;### Nom du fichier, etc...
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 1).Value = $TableauSortie[$i-1][2]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 2).Value = $TableauSortie[$i-1][3]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 3).Value = $TableauSortie[$i-1][4]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 4).Value = $TableauSortie[$i-1][5]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 5).Value = $TableauSortie[$i-1][6]
;~ $oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 6).Value = $TableauSortie[$i-1][1]
;### Fin Nom du fichier, etc...
;~ For $j=6 to $TableauSortie[$i-1][1]
;~ $oWorkbook.sheets("Feuil1").Cells($ExcelRowStart-1, $j).Value = $TableauSortie[$i-1][$j]
;~ Next
Local $ligne=7
For $k=($TableauSortie[$i-1][1])+2 to Ubound($TableauSortie,2)-2
If $TableauSortie[$i-1][$k]<>"" Then
ConsoleWrite($ligne&@CRLF)
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, $ligne).Value = $TableauSortie[$i-1][$k]
$Ligne=$Ligne+1
EndIf
Next
Else
$ExcelRowStart+=2
;### Nom du fichier, etc...
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 1).Value = $TableauSortie[$i-1][2]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 2).Value = $TableauSortie[$i-1][3]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 3).Value = $TableauSortie[$i-1][4]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 4).Value = $TableauSortie[$i-1][5]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 5).Value = $TableauSortie[$i-1][6]
;~ $oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 6).Value = $TableauSortie[$i-1][1]
;### Fin Nom du fichier, etc...
For $j=7 to $TableauSortie[$i-1][1]+1
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart-1, $j).Value = $TableauSortie[$i-1][$j]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart-1, $j).Font.Bold = True
Next
Local $ligne=7
For $k=($TableauSortie[$i-1][1])+2 to Ubound($TableauSortie,2)-2
If $TableauSortie[$i-1][$k]<>"" Then
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, $ligne).Value = $TableauSortie[$i-1][$k]
$Ligne=$Ligne+1
EndIf
Next
Endif
Else
;~ $ExcelRowStart+=2
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 1).Value = $TableauSortie[$i-1][2]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 2).Value = $TableauSortie[$i-1][3]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 3).Value = $TableauSortie[$i-1][4]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 4).Value = $TableauSortie[$i-1][5]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 5).Value = $TableauSortie[$i-1][6]
;~ $oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, 6).Value = $TableauSortie[$i-1][1]
;### Fin Nom du fichier, etc...
For $j=7 to $TableauSortie[$i-1][1]+1
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart-1, $j).Value = $TableauSortie[$i-1][$j]
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart-1, $j).Font.Bold = True
Next
Local $ligne=7
For $k=($TableauSortie[$i-1][1])+2 to Ubound($TableauSortie,2)-2
If $TableauSortie[$i-1][$k]<>"" Then
$oWorkbook.sheets("Feuil1").Cells($ExcelRowStart, $ligne).Value = $TableauSortie[$i-1][$k]
$Ligne=$Ligne+1
EndIf
Next
$ExcelRowStart+=2
Endif
Next
EndFunc