使用TextFieldParser多数民众赞成内置到 VB.NET.谷歌找到了我这个例子
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser _
("C:\test\info.csv")
'Specify that reading from a comma-delimited file'
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
With Me.dgvReport.Rows
.Add(currentRow) 'Add new row to data grid view'
End With
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
31089 次 |
最近记录: |