1.引用 Microsoft Excel 12.0 object library 和 ActiceX Data Objects 2.8 library.

来源:互联网 发布:seo能自学吗 编辑:程序博客网 时间:2024/04/30 03:40

1.引用 Microsoft Excel 12.0 object library 和 ActiceX Data Objects 2.8 library.
现贴上代码:
cn.ConnectionString = “Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=sa;Initial Catalog=AIS20121023174212;Data Source=K3-05A808C6E724”
cn.CursorLocation = adUseClient
cn.Open

Set RS = New ADODB.Recordset
Set RS = Conn.Execute(“exec Pro_NewID”)
RS.MoveFirst
m = RS.Fields(“A”).Value ‘取记录集中某一个特定的值
RS.Close
Set RS = Nothing

Dim XlsAPP As Excel.Application
Dim XlsBook As Excel.Workbook
Dim XlsSheet As Excel.Worksheet
Dim NewName As String
Dim Name As String
Dim i As Integer, j As Long
Dim CmdText1 As String
’ XlsAPP.Visible = True
Set XlsAPP = New Excel.Application
Set XlsBook = XlsAPP.Workbooks.Open(ExcelFile)
Set XlsSheet = XlsBook.Worksheets(1)
If XlsSheet.UsedRange.Cells.Rows.Count = 1 Then
MsgBox “Excel不存在数据”
Else
For i = 2 To XlsSheet.UsedRange.Cells.Rows.Count
CmdText1 = “insert into temp11(FCustomID,FCustomer,FSMS,FGGS,FMaterialID,FMaterial,FType,FAmou,FUuid)” &_
“select’” & XlsSheet.Cells(i, 1) & “’,’” & XlsSheet.Cells(i, 2) & “’,’” & XlsSheet.Cells(i, 3) & “’,’” & XlsSheet.Cells(i, 4) & _
“’,’” & XlsSheet.Cells(i, 5) & “’,’” & XlsSheet.Cells(i, 6) & “’,’” & XlsSheet.Cells(i, 7) & “’,’” & XlsSheet.Cells(i, 8) & “’,’” & m & “’”
Conn.Execute (CmdText1)
Next i
XlsBook.Close
XlsAPP.Quit
Set XlsAPP = Nothing
Set XlsBook = Nothing
Set XlsSheet = Nothing
End If

0 0
原创粉丝点击