嘿所有我试图找出一种方法来纠正我的CSV文件中的错误,然后错误输出 MalformedLineException 。
我的代码是:
Using myreader As New Microsoft.VisualBasic.FileIO.TextFieldParser("c:\temp.csv")
myreader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
myreader.Delimiters = New String() {",", "\n"}
myreader.HasFieldsEnclosedInQuotes = True 'Added
While Not myreader.EndOfData
Try
currentrow = myreader.ReadFields()
错误发生在 currentrow = myreader.ReadFields()上。这是因为CSV的最后一行没有结束引号:
"xx.xxx.xxx.xx","2012-05-15 13:15:54","Bob Barker","bbarker@priceisright.com","
应该是:
"xx.xxx.xxx.xx","2012-05-15 13:15:54","Bob Barker","bbarker@priceisright.com",""
如何更正之前更改 currentrow = myreader.ReadFields()?