我有一个.csv,这是在以下格式:
[TestHeader]FIELDS,"LANGUAGE","LC_NUMERIC","CELLNAME","TESTTYPE","REPORTER","TITLE","STARTDATE","STARTTIME","ENDDATE","ENDTIME"DATATYPE,"Text(80)","Text(80)","Text(64)","Text(80)","Text(80)","Text(80)","Text(12)","Text(20)","Text(12)","Text(20)"
我想把这个数据放在一个多维数组中,这个数组可以模拟它在一个工作表中。如果单元格是空的,那么它在数组中也是空的。
我尝试使用以下代码,但它只将数据放入一个一维数组中,这不适合我的需要。
Dim Delimiter As String
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
Dim LineArray() As String
Dim DataArray() As String
'Inputs
Delimiter = ","
FilePath = emiFilePath
'Open the text file in a Read State
TextFile = FreeFile
Open FilePath For Input As TextFile
'Store file content inside a variable
FileContent = Input(LOF(TextFile), TextFile)
'Close Text File
Close TextFile
'Separate Out lines of data
LineArray() = Split(FileContent, Delimiter, -1, vbTextCompare)
'Read Data into an Array Variable
'Re-Adjust Array boundaries
ReDim Preserve DataArray(UBound(LineArray))
'
'Load line of data into Array variable
For y = LBound(LineArray) To UBound(LineArray)
DataArray(y) = Replace(LineArray(y), Chr(34), vbNullString)
Next y
2条答案
按热度按时间ej83mcc01#
在@Ralph和@VincentG的帮助下
mhd8tkvw2#
当您编写代码时:
您不是在分隔行,而是在分隔由分隔符“”分隔的字段
如果你的简历使用Windows风格的行尾,首先在vbCrLf上分割你的数据。