Chinaunix首页 | 论坛 | 博客
  • 博客访问: 31673
  • 博文数量: 16
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-03 19:49
个人简介

为梦想一直战斗

文章分类

全部博文(16)

文章存档

2013年(16)

我的朋友

分类: Windows平台

2013-10-28 19:57:34

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


阅读(476) | 评论(0) | 转发(0) |
0

上一篇:SQL

下一篇:vb 得到单元格的值

给主人留下些什么吧!~~