|
Sub charu()
aa = Timer
Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim cnn As Object, SQL$, Mypath$, MyFile$, n%
Set cnn = CreateObject("adodb.connection")
cnn.Open "provider=sqloledb;Database=bj_jiekou;Uid=sa;pwd=abc123ABC!@#;data source=fe;"
For i = 2 To 9941
日期 = Cells(i, 1)
凭证类别 = Cells(i, 2)
凭证号 = Cells(i, 3)
摘要 = Cells(i, 5)
科目编码 = Cells(i, 6)
If Cells(i, 7) = "" Then
借方金额 = 0
Else
借方金额 = Cells(i, 7)
End If
If Cells(i, 8) = "" Then
贷方金额 = 0
Else
贷方金额 = Cells(i, 8)
End If
制单人 = Cells(i, 12)
部门编码 = Cells(i, 16)
客户编码 = Cells(i, 18)
供应商编码 = Cells(i, 19)
sql1 = "insert into gl_accvouch_ls (日期,凭证类别,凭证号,摘要,科目编码,借方金额,贷方金额,制单人,客户编码) values('" & 日期 & "','" & 凭证类别 & "','" & 凭证号 & "','" & 摘要 & "','" & 科目编码 & "'," & 借方金额 & "," & 贷方金额 & ",'" & 制单人 & "','" & 客户编码 & "')"
cnn.Execute sql1
Next
cnn.Close
Set cnn = Nothing
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
MsgBox Timer - aa
End Sub
本人在往数据库导入凭证时,由于excel的表格数据有1万行左右,我测试了一下,导入时间是66秒左右,没有有好的方法提高效率那,我的循环方式太笨了。多谢
|
|