1 pièce(s) jointe(s)
Nettoyer un fichier csv mal formé
Bonjour , je suis confronté à un fichier .csv qui est mal formé .(voir pièce jointe)
Résultat la boucle
Code:
Do While Not EOF(numlib)
ne tourne qu'une seule fois alors qu'elle devrait boucler sur toutes les lignes
du fichier .Que faire ?
NB : Le but du programme est de lire le fichier .csv et d'envoyer le flux dans un tableau (aucun travail sur les cellules ou sur un worksheet d'un fichier .xls)
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
| Sub Test(fichiercherche)
Dim Chaine, tableau, i, cloture As Long
Dim numlib As Long
numlib = FreeFile
Open "C:\Documents and Settings\a\Bureau\Seb\" & fichiercherche For Binary As numlib ' #1 '& "\" & fichiercherche & ".txt"
Dim compteur As Integer
compteur = 0 'pour initialiser
Dim tableauindicedate()
Dim tableautotal() 'un tableau avec 7 colonnes
Dim text As String
Do While Not EOF(numlib)
Line Input #numlib, Chaine
Debug.Print Chaine 'mal formée je lis un bloc de lignes alors que je m'attend
'à lire une seule ligne
tableau = Split(Chaine, ",")
text = StrConv(Chaine, vbUnicode)
text = Replace(text, Chr$(26), vbCrLf) ' Remove EOF characters
If IsNumeric(tableau(4)) = True Then
compteur = compteur + 1
ReDim Preserve tableautotal(compteur)
tableautotal(compteur) = tableau
End If
Loop
Close numlib
ReDim tableauindicedate(compteur)
For i = 1 To compteur
tableauindicedate(i) = i
Next i
tableautotal = inversetableautotal(tableautotal)
'tableautotal = dernierecloture(tableautotal) 'j'appelle encore une fonction qui injectera la cotation du jour
Call dessineuneligne(tableauindicedate, compteur, tableautotal)
End Sub |