VB.NET导入具有多个分隔符的CSV文件

时间:2016-04-28 03:44:22

标签: vb.net csv

我出现了一个我要导入数据表的CSV文件。我遇到的挑战是该文件有2个不同的分隔符。前几列用"标签"分隔。其余的用&#34 ;;"。我可以轻松处理这个,但不知道如何处理这两个。到目前为止我所拥有的代码,但很难找到扩展它的方法来导入它的单步:

Public Function LoadFileToDatatable(ByVal FullFilePath As String)
    'Load the Testfile into an datatable
    Dim folder As String = System.IO.Path.GetDirectoryName(FullFilePath)
    Dim filename As String = System.IO.Path.GetFileName(FullFilePath)
    Dim con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & folder & ";Extended Properties=""text;HDR=No;FMT=Delimited"";"
    Dim dt As New DataTable

    Using Adp As New OleDbDataAdapter("Select * From " & filename, con)
        Adp.Fill(dt)

        'Remove the first row as it contains the header data
        Dim theRow As DataRow = dt.Rows(0)
        dt.Rows.Remove(theRow)
    End Using
    Return dt
End Function

0 个答案:

没有答案