|
本帖最后由 aslxt 于 2013-5-10 19:34 编辑
目前只能用逐行读取文本文件的方式可以保存数据的原样,参考代码如下:
Private Sub Command0_Click()
Dim varItem As Variant
With Application.FileDialog(3) 'msoFileDialogFilePicker
.AllowMultiSelect = True '允许选择多个文件
.Filters.Clear
.Filters.Add "CSV Files", "*.CSV" '只显示CSV文件,可根据需要改变
If .Show Then
For Each varItem In .SelectedItems
DR varItem
Next
End If
End With
End Sub
Function DR(ByVal MYspath As String)
Dim SQL, STR
Dim i As Long
Dim A
Close #1
i = 0
Open MYspath For Input As #1
Do While Not EOF(1)
Line Input #1, STR ' 逐行读入
i = i + 1
A = Split(STR, ",") '这里不允许csv文件的数据设为千分位,文本字符间不能有半角逗号
If i > 1 Then
SQL = "INSERT INTO tbl_Export ( [VENDOR NO], [CUSTOMER NO], [INVOICE NO], [BL DATE], [MODEL NO], QTY, PRICE, AMOUNT ) VALUES (" & _
"""" & A(0) & """" & "," & """" & A(1) & """" & ", " & """" & A(2) & """" & ", " & "#" & A(3) & "#" & "," & """" & A(4) & """" & ", " & A(5) & ", " & A(6) & ", " & A(7) & " )"
Debug.Print SQL
CurrentProject.Connection.Execute SQL
End If
Loop
Close #1
End Function
|
|