IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Parser fichier csv dans tableau


Sujet :

VBScript

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Août 2009
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2009
    Messages : 37
    Points : 35
    Points
    35
    Par défaut Parser fichier csv dans tableau
    bonjour
    j ai trouver ce code sur le net pour lire un fichier csv
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    Set FSO = CreateObject("Scripting.FileSystemObject") 
    Set Ftxt = FSO.OpenTextFile("e:\ScanReseaux.csv") 
     
    Do While Not Ftxt.AtEndOfStream  
    MaVariable = Ftxt.Readline  
     
    For Each strItem In CSVParse(mavariable) 
    '    wscript.Echo strItem ' affiche le contenu du fichier csv, champs apres champs ... 
    '... inserer le code ici 
     
    	MsgBox stritem
     
     
    Next 
    Loop 
    Ftxt.Close 
     
    Function CSVParse(ByVal strLine) 
        Dim arrFields 
        Dim blnIgnore 
        Dim intFieldCount 
        Dim intCursor 
        Dim intStart 
        Dim strChar 
        Dim strValue 
     
        Const QUOTE = """" 
        Const QUOTE2 = """""" 
     
        If (Len(Trim(strLine)) = 0) then 
            CSVParse = Array() 
            Exit Function 
        End If 
        blnIgnore = False 
        intFieldCount = 0 
        intStart = 1 
        arrFields = Array() 
        strLine = strLine & "," 
     
        For intCursor = 1 To Len(strLine) 
     
            strChar = Mid(strLine, intCursor, 1) 
            Select Case strChar 
                Case QUOTE 
     
                    blnIgnore = Not blnIgnore 
                Case "," 
                    If Not blnIgnore Then 
     
                        ReDim Preserve arrFields(intFieldCount) 
     
                        If (intCursor - intStart > 0) Then 
     
                            strValue = Mid(strLine, intStart, _ 
                                intCursor - intStart) 
     
                            If (Left(strValue, 1) = QUOTE) Then 
                                arrFields(intFieldCount) = _ 
                                    Replace(Mid(strValue, 2, _ 
                                    Len(strValue) - 2), QUOTE2, QUOTE) 
                            Else 
                                arrFields(intFieldCount) = strValue 
                            End If 
                        Else 
                            arrFields(intFieldCount) = Empty 
                        End If 
     
                        intFieldCount = intFieldCount + 1 
                        intStart = intCursor + 1 
                    End If 
            End Select 
        Next 
          CSVParse = arrFields 
    End Function
    j aimerais savoir comment faire pour inserer chaque champ dans une champ de tableau afin de pouvoir ensuite generer une liste deroulant dans un module hta avec un des champ
    merci d avance

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Août 2009
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2009
    Messages : 37
    Points : 35
    Points
    35
    Par défaut
    bonjour
    apres une journee de recherche sur google et le forum j ai trouve une solution tout seul
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    <html>
    <head>
    <title>My HTML application</title>
    <HTA:APPLICATION
      APPLICATIONNAME="My HTML application"
      ID="MyHTMLapplication"
      VERSION="1.0"/>
    </head>
     
    <script language="VBScript">
    	Const ForReading = 1
    	Const ForWriting = 2
    	Const ForAppending = 8
         Dim fso,f
     
    Sub Window_OnLoad
      'This method will be called when the application loads
      'Add your code here
      test
    End Sub
     
    Sub test
     
     
       strNewFile = "e:\ScanReseaux2.csv"
     
       Set fso = CreateObject("Scripting.FileSystemObject")
     
     
     
      Set f = fso.OpenTextFile(strNewFile,ForReading)
     
        Do Until f.AtEndOfStream
            strLine = f.ReadLine
     
            elem = split(strLine,",")
     
     
            elem(2)=Replace(elem(2),Chr(34),"")
     
            Set oObjOption = Document.createElement("OPTION")
            	oObjoption.Text= elem(2)
            		Provider.add(oObjoption)
             Loop
     
     
     
        f.close
     
     End Sub 
     
     
     
     
     
     
    </script>
     
    <body text=black bgcolor=#E6E2AF>
    <body text=black bgcolor=#E6E2AF>
     
    <SELECT name="Provider" id="provider"/></SELECT>
     
     
    </body>
    </html>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. charger ligne fichier csv dans tableau C
    Par nhella22 dans le forum Débuter
    Réponses: 6
    Dernier message: 21/04/2011, 20h28
  2. stocker des valeurs entiéres dns un fichier csv dans un tableau
    Par industrielle dans le forum Entrée/Sortie
    Réponses: 3
    Dernier message: 22/03/2009, 18h40
  3. Réponses: 6
    Dernier message: 05/02/2009, 09h34
  4. [CSV] Mettre un fichier CSV dans un tableau
    Par tahiboy dans le forum Langage
    Réponses: 5
    Dernier message: 17/06/2007, 11h36
  5. Mettre un fichier csv dans un tableau à deux dimensions
    Par neeux dans le forum Général Python
    Réponses: 5
    Dernier message: 05/03/2007, 16h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo