|
直接用二进制打开操作不更好?请参考以下代码,适合打开CSV和TXT格式
f = Application.GetOpenFilename
Dim LFile As Long, DAT() As Byte, ST As String, aa As String
LFile = FileLen(f) - 1
ReDim DAT(LFile) As Byte
Open f For Binary As #1
Get #1, , DAT
Close #1
ST = DAT
If DAT(0) = &HFF And DAT(1) = &HFE Then '如果是Unicode编码文件
ST = Mid(ST, 2)
Else
ST = StrConv(ST, vbUnicode)
End If
If UBound(Split(ST, Chr(13) & Chr(10))) > 0 Then
arr = Split(ST, Chr(13) & Chr(10))
Else
arr = Split(ST, Chr(10))
End If
ReDim arr1(0 To UBound(arr), 0 To UBound(Split(arr(i), ","))) '转换二维数组
If UBound(arr) > 0 Then
For i = 0 To UBound(arr)
For j = 0 To UBound(Split(arr(i), ","))
If i <= UBound(arr1) And j <= UBound(arr1, 2) Then arr1(i, j) = Split(arr(i), ",")(j)
Next j
Next i
End If
[ 本帖最后由 彭希仁 于 2008-11-22 09:15 编辑 ] |
|