如题,数据库中有些字段我不想导出到excel中,用select 字段,这样屏蔽的话,程序里面又有很多字段要用到,所以问下指定字段怎么处理,度娘没告诉我,求教下大家,谢谢!!

解决方案 »

  1.   

    ’经实际测试,以下代码数据库和Excel之间互相导入导出,完全成功!
    Private Sub Command1_Click()
        'access导出到excel
        Dim db As New ADODB.Connection
        Dim sPath As String
        
        db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\Test\db1.mdb Persist Security Info=False"
        
        sPath = App.Path + "\backup.xls"
        If Dir(sPath) <> "" Then
            Kill sPath
        Else
        
        Call db.Execute("select * into Sheet1  In '" & sPath & "' 'excel 8.0;' from 表1")
            MsgBox "导出成功", vbOKOnly, "提示"
        End If
        
        db.Close
        Set db = Nothing
    End SubPrivate Sub Command2_Click()
        '从excel导出到 access
       Dim db As New ADODB.Connection
        Dim sPath As String
        
        db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\Test\db1.mdb;Persist Security Info=False"
        
        sPath = App.Path + "\backup.xls"
        Call db.Execute("select * into Table4 From [Sheet1$]  In '" & sPath & "' 'excel 8.0;'")
            
        db.Close
        Set db = Nothing
    End Sub
      

  2.   

    谢谢1楼,提示in 附近有语法错误,已经在路径新建了excel文件
      

  3.   

    我又重新测试了一下,没有问题啊Private Sub Command1_Click()
        'access导出到excel
        Dim db As New ADODB.Connection
        Dim sPath As String
        
        db.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\测试数据\db1.mdb; Persist Security Info=False"
        
        sPath = App.Path + "\backup.xls"
        If Dir(sPath) <> "" Then
            Kill sPath
        Else
        
        Call db.Execute("select * into Sheet1  In '" & sPath & "' 'excel 8.0;' from 表1")
            MsgBox "导出成功", vbOKOnly, "提示"
        End If
        
        db.Close
        Set db = Nothing
    End SubPrivate Sub Command2_Click()
        '从excel导出到access
        Dim db As New ADODB.Connection
        Dim sPath As String
        
        
        sPath = App.Path + "\测试数据\"
        
        db.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath & "\db1.mdb;Persist Security Info=False"
        Call db.Execute("select * into Table4 From [Sheet1$] In '" & sPath & "\Book2.xls' 'excel 8.0;'")
            
        db.Close
        Set db = Nothing
    End Sub