代码实现的功能是:从指定的EXCEL文件中抓取一些数据插入表中
控制点
1指定的excel 中要有sheet
2sheet中要有一个名为“upload”的文件
代码如下:
'check sheet's names must contain upload
intCsheet = xlBook.Worksheets.Count
If intCsheet = 0 Then
MsgBox "The execl file " & strfilename & " has no data!"
xlBook.Close (True) '关闭EXCEL工作簿
xlExcel.Quit '关闭EXCEL
Set xlExcel = Nothing '释放EXCEL对象
insert_tepmtable = False
Exit Function
End If
For intI = 1 To intCsheet
If UCase(xlBook.Worksheets(intI).NAME) = "UPLOAD" Then
Exit For
End If
Next
If intI > intCsheet Then
MsgBox "The execl file " & strfilename & " has no upload sheet !"
xlBook.Close (True) '关闭EXCEL工作簿
xlExcel.Quit '关闭EXCEL
Set xlExcel = Nothing '释放EXCEL对象
insert_tepmtable = False
Exit Function
End If
Set xlSheet = xlBook.Worksheets("upload")
'get excel's data
With xlSheet
For intJ = 2 To 65535
If Len(Trim(.Cells(intJ, 1).Value)) <> 0 Then
strsql = "insert into tmp_uploadprice" & _
" values(" & CLng(.Cells(intJ, 1).Value) & _
",'" & CStr(.Cells(intJ, 2).Value) & _
"',' '" & _
"," & CDbl(.Cells(intJ, 4).Value) & ")"
DbsBpcs.Execute strsql
EDN If
NEXT