麻烦老师朋友们给个用VB操作EXCEL的例子学习也就是在VB环境中用SQL的形式操作EXCEL工作表!

解决方案 »

  1.   

    工程--引用 Microsoft ActiveX Data Objects 2.5 LibraryDim adoConnection As New ADODB.Connection
    Dim adoRecordset As New ADODB.Recordset
    adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0Persist Security Info=False;" & "Data Source=C:\ABC.XLS;Extended Properties='Excel 8.0;HDR=Yes'"
    adoRecordset.Open "select * from [sheet1$]", adoConnection,adOpenKeyset, adLockOptimistic
    Set MSHFlexGrid1.DataSource = adoRecordset
      

  2.   

    工程--引用 Microsoft ActiveX Data Objects 2.5 Library
    Private Sub Command1_Click()
       Dim adoConnection As New ADODB.Connection
       Dim adoRecordset As New ADODB.Recordset
       adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;" & "Data Source=C:\1.XLS;Extended Properties='Excel 8.0;HDR=Yes'"
       adoRecordset.Open "select * from [sheet1$]", adoConnection, adOpenKeyset, adLockOptimistic
       Set MSHFlexGrid1.DataSource = adoRecordset
    End Sub
      

  3.   

    恩,代码用楼上的即可,注意
    1.引用 Microsoft ActiveX Data Objects 2.* Library       2.1以上的
    2.excel版本是2003以下的,如果是2007版的,要转换为低版本的