用 Microsoft Access 就可以打开 CSV 文件的。
然后再保存成mdb就行了。
CSV、MDB格式转换程序:
'///
'CSV < - >MDB Convert Tool
'Written By gyawjk
'///
Option Explicit
Private Sub Command1_Click()
On Error GoTo ErrHandler
CommonDialog1.FileName = ""
CommonDialog1.CancelError = True
CommonDialog1.Filter = "CSV File(*.csv;*.txt)|*.csv;*.txt"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Text1.Text = CommonDialog1.FileName
End If
Exit Sub
ErrHandler:
MsgBox "Error:" & Err.Description, vbCritical, "Error"
End Sub
Private Sub Command2_Click()
On Error GoTo ErrHandler
CommonDialog1.FileName = ""
CommonDialog1.CancelError = True
CommonDialog1.Filter = "Access File(*.mdb)|*.mdb"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Text2.Text = CommonDialog1.FileName
End If
Exit Sub
ErrHandler:
MsgBox "Error:" & Err.Description, vbCritical, "Error"
End Sub
Private Sub Command3_Click()
If Option1.Value = True Then
If Dir(Text1.Text) = "" Then
MsgBox "CSV文件不存在!", vbCritical, "错误"
Exit Sub
End If
If CSV2MDB(Text1.Text, Text2.Text) = True Then
MsgBox "导入表成功!", vbInformation, "提示"
End If
Else
If Dir(Text2.Text) = "" Then
MsgBox "CSV文件不存在!", vbCritical, "错误"
Exit Sub
End If
If MDB2CSV(Text2.Text, Text1.Text, "Book1") Then
MsgBox "导出CSV成功!", vbInformation, "提示"
End If
End If
End Sub
Private Function CSV2MDB(CSVFileName As String, MDBFileName As String, Optional TableName As String = "") As Boolean
On Error GoTo ErrHandler
Dim strTemp As String
Dim strCSVFile As String, strCSVLineSplit As String
Dim iCSVLineCount As Integer, iCSVFieldCount As Integer
Dim strArrCSVLine() As String, strArrCSVHead() As String, strArrCSVData() As String
Dim i As Integer, j As Integer, Ret As Long
Dim ADOXCat As ADOX.Catalog, ADOXTable As ADOX.Table
Dim ADOConn As ADODB.Connection, ADORs As ADODB.Recordset
Dim strCn As String
Dim FileNum As Integer
CSV2MDB = False
FileNum = FreeFile
Open CSVFileName For Input As FileNum
While Not EOF(FileNum)
strTemp = ""
Line Input #FileNum, strTemp
If Trim(strTemp) <> "" And Trim(strTemp) <> vbCrLf Then
If strCSVFile = "" Then
strCSVFile = strTemp
Else