ImportCSV

dim a as  Dictionary(Of Long, String())

a = ImportCSV(FileName)

 

■以下クラス

Imports System.Text

Public Class ImportCsv
Implements IImportFile
Public Function ImportExecute(ByVal filePath As String, ByVal Optional isHeaderImport As Boolean = False, ByVal Optional isHaveDoubleQuate As Boolean = False,
ByVal Optional isTrim As Boolean = False, ByVal Optional encode As String = STR_ENC_SHIFTJIS, ByVal Optional headerCheckString As String = "") As Dictionary(Of Long, String()) Implements IImportFile.ImportExecute
Using objIoTFP As New Microsoft.VisualBasic.FileIO.TextFieldParser(filePath, Encoding.GetEncoding(encode))
'読み込み時の設定
With objIoTFP
'区切り文字をカンマに設定
.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
.SetDelimiters(STR_COMMA)
'空白に対するTrim
.TrimWhiteSpace = isTrim
'ダブクオテーション有無
.HasFieldsEnclosedInQuotes = isHaveDoubleQuate
End With

Dim dic As New Dictionary(Of Long, String())
Dim count As Long
Dim header As String()
header = objIoTFP.ReadFields()
If Not isHeaderOk(String.Join(STR_COMMA, header), headerCheckString) Then
Utils.Alert("ファイルレイアウトが正しくありません。")
Return Nothing
End If
If isHeaderImport Then
dataAdd(count, dic, header)
End If
'CSV読み込み実行
While Not objIoTFP.EndOfData
dataAdd(count, dic, objIoTFP.ReadFields())
End While
Return dic
End Using
End Function
Private Function IsHeaderOk(ByVal header As String, ByVal headerCheckString As String) As Boolean
Return header = headerCheckString
End Function
Private Sub DataAdd(ByRef count As Long, ByRef dic As Dictionary(Of Long, String()), ByVal addData As String())
count += 1
dic.Add(count, addData)
End Sub
End Class