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
| Private Sub BackgroundWorker1_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Try
Dim Separator = ToolStripTextBox1.Text
Dim filename As String
OpenFileDialog1.ShowDialog()
filename = OpenFileDialog1.FileName
Dim sr As New IO.StreamReader("C:\Users\PC- TOSHIBA\Desktop\TEST.txt")
Dim dt As New DataTable
Dim newline() As String = sr.ReadLine.Split(Separator)
dt.Columns.AddRange({New DataColumn("Identifiant"), New DataColumn("REF"), New DataColumn("Fournisseur")})
While (Not sr.EndOfStream)
newline = sr.ReadLine.Split(Separator)
Dim newrow As DataRow = dt.NewRow
Try
Dim Fournisseur() As String = Split(newline(0), "@")
newrow.ItemArray = {newline(0), newline(1), Fournisseur(1)}
dt.Rows.Add(newrow)
Catch ex As Exception
End Try
End While
DataGridView1.DataSource = dt
Catch ex As Exception
'MsgBox("Une erreur a été levée, vérifier que le fichier soit au bon format : 2 colonnes---> [mail : réf], le séparateur est modifiable dans le menu")
Exit Sub
End Try
Label1.Text = "Enregistements : " & DataGridView1.RowCount
End Sub |
Partager