引用Excel的使用然后打开excel文件,一个一个去处cell的值放进数据库即可

解决方案 »

  1.   

    Email?
    有源码,可以发给你!
      

  2.   

    用vba就可以实现。vba中可以引入ado组件,30分钟,就可以搞定,我曾将用excel中向oracle数据库中插入测试用的数据。很方便。
      

  3.   

    Dim oApp As New Excel.Application
            Dim oBook As Excel.Workbook
            Dim oSheet As Excel.Worksheet
            
            With oApp
                .AlertBeforeOverwriting = False
                .Workbooks.Open sFile
                .DisplayAlerts = False
                Set oBook = .Workbooks(1)
            End With
            lSheets = oBook.Worksheets.Count
            On Error GoTo RollBack
            
            goCon.BeginTrans
            
            For lIndex = 1 To lSheets
                Set oSheet = oBook.Worksheets(lIndex)
                oSheet.Activate
                sSheetName = cboName.Text
                nYear = Val(cboYear.Text)
                oSheet.Range("A1").Select
    For nMonth = CN("A") To CN("L")
                        fRead = True
                        nTrueDay = 0
                        nWeekNo = 1
                        pbar.Value = nMonth
                        fraProgress.Caption = "Processing " & xMonthName(nMonth) & " Data..."
                        For nDay = 1 To 50
                            sRaw = Trim(oSheet.Cells(nDay, nMonth))
                            If sRaw = "" Then
                                If fRead = True Then
                                    fRead = False
                                    nWeekNo = nWeekNo + 1
                                End If
                            Else
                                If fRead = False Then fRead = True
                                lDataNumbers = lDataNumbers + 1
                                nTrueDay = nTrueDay + 1
                                dDate = DateSerial(nYear, nMonth, nTrueDay)
                                If nTrueDay > GetMonthDays(dDate) Then
                                    Alert "Error Days - Stopped! See Details in events log"
                                    PutToLog "Error Days", "Import Excel", "File:" & sFile & _
                                        ",there are more days set while read cell:" & Chr(nMonth) & nDay
                                    GoTo RollBack
                                End If
                                lData = Val(sRaw)
                                If oSave.Add(sName, dDate, nNo, lData, 0, 0, 0, "") = False Then GoTo RollBack
                            End If
                        Next
                    Next
                End If
                
    Next
            Alert lDataNumbers & "  Rows Imported" & vbCrLf
        
    goCon.CommitTrans
        GoTo CleanRow
    RollBack:
        goCon.RollbackTrans
    CleanRow:
        oApp.Quit
        Set oSave = Nothing
        Set oSheet = Nothing
        Set oBook = Nothing
        Set oApp = Nothing
        cmdCancel.Enabled = True
        cmdImport.Enabled = True
    '    Unload Me
        Me.Height = clNormal
      

  4.   

    Dim gObj_Connection As New ADODB.Connection
    Dim gObj_Command As New ADODB.Command
    Dim gObj_Dataset As New ADODB.Recordset
    Const strConnection = "Provider=OraOLEDB.Oracle.1;Password=manager;Persist Security Info=True;User ID=system;Data Source=faxsrv"Private Sub CommandButton1_Click()
        gObj_Connection.Open strConnection, "system", "manager", adConnectUnspecified
        gObj_Dataset.Open "select * from dual", gObj_Connection, adOpenUnspecified, adLockOptimistic, -1
    End Sub
      

  5.   

    原来写的那个现成的找不到了,上面我只给你写了个思路,那样操作就可以打开数据集了。如果要插入数据可以使用ADODB.Command对象,ado你应该会用吧。又不明白的地方来信:[email protected]
      

  6.   

    最簡單的方法
    打開SQL在Enterprise Manager 打開要加入的數据庫﹐按右鍵Imput Data.....
    一路下去﹐注意選取Excel 8.0的類型檔案就是了要么用SQL代碼DAO﹑ADO都行