Private Sub Command1_Click()
Dim ex As New Excel.Application
Dim nb As Excel.Workbook
Dim l, r As Integer
Dim df As Date
df = InputBox("请输入日期:(例如:2013-10-23)")
de = DateAdd("d", 1, df)
ex.Visible = True
Set nb = ex.Workbooks.Open("C:\FameView\ReportFile\aaa.xls")
Set conn = CreateObject("ADODB.Connection")
strConn = "Driver={SQL Server};Server=(local);Database=UserDatabase;Uid=;Pwd=;"
conn.Open strConn
Set rs = CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM 日报表A WHERE (DT > '" & Format(df, "YYYY-MM-DD") & "') and (DT < '" & Format(de, "YYYY-MM-DD") & "')"
rs.Open strSQL, conn, 2, 2
If rs.bof = True Then
End If
r = 10
While (rs.bof = False And rs.EOF = False)
l = 2
'添加新记录rs("DUST")
ex.Cells(r, l) = rs("入烟尘")
ex.Cells(r, l + 1) = rs("入烟尘折算")
ex.Cells(r, l + 2) = rs("入烟尘排放")
ex.Cells(r, l + 3) = rs("入SO2")
ex.Cells(r, l + 4) = rs("SO2入折算")
ex.Cells(r, l + 5) = rs("SO2入排放")
ex.Cells(r, l + 6) = rs("入流量")
ex.Cells(r, l + 7) = rs("入O2")
ex.Cells(r, l + 8) = rs("入温度")
l8 = l8 + rs("入温度")
ex.Cells(r, l + 10) = rs("DT")
Rows("10:10").Select
Selection.Copy
rs.MoveNext
r = r + 1
Rows(r & ":" & r).Select
Selection.Insert Shift:=xlUp
'Selection.EntireRow.Insert
Wend
Rows(r & ":" & r).Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
阅读(505) | 评论(0) | 转发(0) |