我正在使用 VB 2005,如何打开 CSV 文件并读取列/行并在数据网格中显示值?
CSV 文件示例:
杰史密斯,[电子邮件受保护]
然后我想对每一行(即每个用户)执行一个操作,我该怎么做?
正如你所知,我是一个新手,但很乐意学习。
Thanks
Use the 文本字段解析器 that's 内置于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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)