我想把excel表格的内容导入到access数据库中,然后在VB的控制里显示出来,不知道该怎么做。请大家帮帮忙

解决方案 »

  1.   

    以前 我用打开EXCEL对象的 现在 我一般叫客户先把数据复制到粘贴板  
    我直接处理粘贴板的数据 、
    这样可以避免兼容性问题
      

  2.   

    参考:
    http://topic.csdn.net/u/20080828/09/44109f8f-666b-4fa1-88be-e784c66eddf1.html
      

  3.   

    把下面代码稍改下就行了
    Dim excel_app As Object 
    Dim excel_sheet As Object 
    Dim db As Database 
    Dim AccessPath As String, AccessTable As String 
    Dim sql As String 
    Dim frm As New frmMessage 
    Dim msg As String 
        
        ADOsdb.BeginTrans 
        
    '    With ADOsdb 
    '        If .State <> adStateOpen Then 
    '            .CursorLocation = adUseClient 
    '            .ConnectionString = gsOdbcName 
    '            .Open 
    '        End If 
    '    End With 
        With dlgCommonDialog 
            .DialogTitle = "打开" 
            .CancelError = False 
            'ToDo:  设置  common  dialog  控件的标志和属性 
            .Filter = "Excel文件  (*.xls) ¦*.xls" 
            .ShowOpen 
            If Len(.FileName) = 0 Then 
                    Exit Sub 
            End If 
            sfile = .FileName 
        End With   
      AccessPath = lcspath & "\db.mdb"                                '数据库路径 
      excelpath = sfile                                                  '电子表格路经 
      AccessTable = "db"                                                '数据库内表格 
      
      msg = Trim(InputBox("请输入表名,如sheet1或sheet2:", "工作表", "sheet1")) 
    '  msg = Str(msg) 
      sheet = msg                                            '电子表格内工作表 
      Set db = OpenDatabase(excelpath, True, False, "Excel 8.0") '打开电子表格文件 
      sql = ("Select * into [;database=" & AccessPath & "]." & AccessTable & " FROM [" & sheet & "$]") 
    '  sql = ("Select * into [;database=" & AccessPath & "]." & AccessTable & " FROM [" & sheet & "]") 
        
      If sheet = "" Then 
          MsgBox "您选择的EXCEL表不存在,请重新导入!", vbInformation, "抱歉!" 
          Exit Sub 
      End If 
      
      If deltable = 1 Then 
        With ADOsdb 
            .Execute "drop table db", , adCmdText 
        End With 
      End If 
      
      ADOsdb.CommitTrans   db.Execute (sql)                                        '将电子表格导入数据库 
                    
                    
      ShowMessage "正在导入EXCEL表,请您稍等..." 
      Timer1.Enabled = True 
      

  4.   

    学习下!以上代码是不是直接把EXCEL导入ACCESS表中呢..