问题在这::: 我要导入数据库的 .xls 的格式很不规则,你能教我一个直接对单元表格操作的方法吗?
就是先从单元表格中取出数据,在放入数据库中。我实在对 excel 太不熟悉了!
谢谢!!!

解决方案 »

  1.   

    这样好吗?你把XLS发给我,我帮你写一个例子在里头,你到时看源代码就可以学会了。
    [email protected]
      

  2.   

    我发给你了!
    我的mail :[email protected]
      

  3.   

    很规则啊!你要写到什么数据库中呢?ACCESS OR MSSQL!
      

  4.   

    简单,使用ADO:Dim cn As ADODB.Connection
    Dim rsT As ADODB.Recordset
    Set cn = Createobject("ADODB.Connection")
    With cn
    .Provider = "MSDASQL"
    .ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};" & _
    "DBQ=xls文件物理路径" 
    .CursorLocation = adUseClient
    .Open
    End Withset rsT=createobject("adodb.recordset")
    rsT.open "SELECT * FROM [Sheet1$]",cn,0,1
    ......
      

  5.   

    引用ADO2
    COPY下列代码。
    Dim cnn As New ADODB.ConnectionSub open_db()
        
        Dim strnn As String
        strnn = ""  '联接字串。
        cnn.Open strnn
    End SubSub write_data()    Dim i As Integer
        Dim j As Integer
        Dim str1 As String
        i = 2
        With Sheets("sis.xls")
            Do While .Cells(i, 1) <> ""
                'Debug.Print .Cells(i, 1)
                str1 = "insert into t1(f1,f2,f3....) values('"
                For j = 1 To 15
                    str1 = str1 & .Cells(i, j) & "','"
                Next j
                str1 = Left(str1, Len(str1) - 2) & ")"
                cnn.Execute str1
                i = i + 1
            Loop
        End With
    End Sub
    试试!有问题可以再问我。
      

  6.   

    忘了说明,我的代码是VBA的,也就是在EXECEL中执行的。
      

  7.   

    给我你的email : 我发给你一个文件,你能导进去吗????
      

  8.   

    可以的,因为这种方法我用的太多了,只是因为你的要引入到MSSQL中比较烦,所以我没有试,但我的方法一定可以。
      

  9.   

    你没看到我给你的代码吗?Dim cnn As New ADODB.ConnectionSub open_db()
        
        Dim strnn As String
        strnn = ""  '联接字串。
        cnn.Open strnn
    End SubSub write_data()    Dim i As Integer
        Dim j As Integer
        Dim str1 As String
        i = 2
        With Sheets("sis.xls")
            Do While .Cells(i, 1) <> ""
                'Debug.Print .Cells(i, 1)
                str1 = "insert into t1(f1,f2,f3....) values('"
                For j = 1 To 15
                    str1 = str1 & .Cells(i, j) & "','"
                Next j
                str1 = Left(str1, Len(str1) - 2) & ")"
                cnn.Execute str1
                i = i + 1
            Loop
        End With
    End Sub