Page 1 sur 1

[..] Suppression caractères dans un array

Posté : lun. 12 janv. 2015 10:50
par Hugues
Bonjour,

Meilleurs voeux à tous,

Le retour des fêtes doit être difficile, car j'obtiens un tableau avec la fonction _StringToArray2D().

Ce que je veux faire est simple, dans mon tableau il y a des " ' " que je veux supprimer et des "." à transformer en "," car je fais une extraction Excel.

Et là je bloque... Je ne sais pas comment faire... :shock: :shock:

Ci joint mon code:

Code : Tout sélectionner

[spoiler=]
Func _ExportFileToExcel()

    $aString = _StringToArray2D($Display, @CRLF, ";", 1)
    _ArrayDisplay($aString)

    If $aString = "" Then Return MsgBox(64, "", "Aucune donnée à exporter.", -1, $MainGUI)
    SplashTextOn("", "Exportation vers Excel des données " & $FileToOpen & " en cours..." & @CRLF & "Veuillez patienter...", 550, 80, -1, -1, 49)
    Local $oAppl = _Excel_Open()
    If @error Then Exit MsgBox(64, "", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended, $MainGUI)

    Local $oWorkbook = _Excel_BookNew($oAppl)
    If @error Then
        MsgBox(64, "", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended, $MainGUI)
        _Excel_Close($oAppl)
        Exit
    EndIf

    _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aString, "A1", True, True)

    $oWorkbook.ActiveSheet.Columns("A:M").AutoFit
    SplashOff()

EndFunc

[/spoiler]
Merci d'avance.

Re: [..] Suppression caractères dans un array

Posté : lun. 12 janv. 2015 10:58
par DimVar
Bonjour,

Un script pour ca ? CTRL + H....

Cdlt, Dimvar.

Re: [..] Suppression caractères dans un array

Posté : lun. 12 janv. 2015 12:47
par TomAijerrie
Voici une idée de fonction, à reprendre bien sûr.
Je n'ai pas pu le tester, les erreurs doivent être nombreuses...

Code : Tout sélectionner

Func array_excel_perso(ByRef $array)
    Switch UBound($array ,0)
        Case 1; tableau à 1D
            For $i = 0 To UBound($array, 1) -1
                $array[$i] = StringReplace($array[$i]," ' ","")
                $array[$i] = StringReplace($array[$i],".",",")
            Next
            Return $array
        Case 2;tableau 2D
            For $i = 0 To UBound($array,1) -1
                For $j = 0 To UBound($array,2) -1
                    $array[$i] = StringReplace($array[$i]," ' ","")
                    $array[$i] = StringReplace($array[$i],".",",")
                Next
            Next
            Return $array
    EndSwitch
    Return SetError(-1,0,-1);$array n'est pas valide
EndFunc

Re: [..] Suppression caractères dans un array

Posté : lun. 12 janv. 2015 14:23
par Hugues
Ok merci je regarde tout ça

Re: [..] Suppression caractères dans un array

Posté : lun. 12 janv. 2015 14:46
par mikell
@TomAijerrie
Petite erreur d'inattention :wink:

Code : Tout sélectionner

        Case 2;tableau 2D
            For $i = 0 To UBound($array,1) -1
                For $j = 0 To UBound($array,2) -1
                    $array[$i][$j] = StringReplace($array[$i][$j],"'","")   ; "'" et [$i][$j]
                    $array[$i][$j] = StringReplace($array[$i][$j],".",",")
                Next
            Next

Re: [..] Suppression caractères dans un array

Posté : mar. 13 janv. 2015 14:14
par TomAijerrie
Bien vu.