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
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
有源码,可以发给你!
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
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
打開SQL在Enterprise Manager 打開要加入的數据庫﹐按右鍵Imput Data.....
一路下去﹐注意選取Excel 8.0的類型檔案就是了要么用SQL代碼DAO﹑ADO都行