Précédent   Forum du club des développeurs et IT Pro > Autres langages > Général Visual Basic 6 et VBScript > VBScript
VBScript Le forum d'entraide sur VBScript. Avant de poster -> La FAQ VBScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 21/11/2012, 11h23   #1
djdmd
Invité régulier
 
Inscription : août 2009
Messages : 29
Détails du profil
Informations personnelles :
Âge : 42

Informations forums :
Inscription : août 2009
Messages : 29
Points : 9
Points : 9
Par défaut Parser fichier csv dans tableau

bonjour
j ai trouver ce code sur le net pour lire un fichier csv
Code :
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
djdmd est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/11/2012, 16h40   #2
djdmd
Invité régulier
 
Inscription : août 2009
Messages : 29
Détails du profil
Informations personnelles :
Âge : 42

Informations forums :
Inscription : août 2009
Messages : 29
Points : 9
Points : 9
bonjour
apres une journee de recherche sur google et le forum j ai trouve une solution tout seul
Code :
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>
djdmd est déconnecté   Envoyer un message privé Réponse avec citation 20
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 06h23.


 
 
 
 
Partenaires

Hébergement Web