回复:技术专题探讨-WinCC实现报表的不同方法及其应用

天涯宿命

  • 帖子

    6
  • 精华

    2
  • 被关注

    2

论坛等级:游民

注册时间:2009-03-04

普通 普通 如何晋级?

发布于 2009-03-04 22:30:56

0楼

我是这样做的,通过VBS把WINCC实时数据些到我建立好的SQL数据库中,然后在WINCC界面上做一个查询按钮,按你所要的日期或时间从数据库中读出相应数据。下面,我把查询的部分代码贴出。
Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)
Dim strDate,strTime
Dim strcn,cn
Dim rs
Dim strSQL
Dim comm
Dim i
‘建立数据库连接
strcn="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DBNAEM;Data Source=dbserver\wincc"
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
Set comm=CreateObject("ADODB.Command")
cn.ConnectionString=strcn
cn.cursorlocation=3
cn.Open
comm.commandtype=1
comm.activeconnection=cn
'**********************************************************
'**********************************************************
Dim StrYear
Set StrYear = HMIRuntime.Tags("StrYear")
stryear.Read
Dim StrMonth
Set StrMonth = HMIRuntime.Tags("StrMonth")
strmonth.Read
Dim StrDay
Set StrDay = HMIRuntime.Tags("StrDay")
strday.Read

strDate=stryear.Value +"-"+strmonth.Value+"-"+strday.Value

Dim StrHour
Set StrHour = HMIRuntime.Tags("StrHour")
StrHour.Read
Dim StrMinute
Set StrMinute = HMIRuntime.Tags("StrMinute")
StrMinute.Read

strTime=StrHour.Value+":"+StrMinute.Value
'*************************************************************
建立EXCEL对象
Dim objexcelApp
Set objexcelApp=CreateObject("excel.application")
With objexcelApp
.visible=True
.workbooks.open"d:\SPSQLServer_2008\ExcelReport\SOURCE.xls"打开EXCEL模板
.activeworkbook.activesheet.select
.displayalerts=False
End With
'****************************************************************
查询数据库中相应数据,然后写到相应的EXCEL单元格中。
i=4 表示第四行
strSQL="select * from Station_1 where St1_Date='"&strDate&"'and St1_Time='"&StrTime&"'"
comm.commandtext=strSQL
Set rs=comm.execute
If Not rs.eof Then
With objexcelApp.worksheets(1)
objexcelApp.Worksheets(1).cells(i,3).value=rs.fields(0).value
objexcelApp.Worksheets(1).cells(i,4).value=rs.fields(1).value
objexcelApp.Worksheets(1).cells(i,5).value=rs.fields(2).value
objexcelApp.Worksheets(1).cells(i,6).value=rs.fields(3).value
objexcelApp.Worksheets(1).cells(i,7).value=rs.fields(4).value
objexcelApp.Worksheets(1).cells(i,8).value=rs.fields(5).value
objexcelApp.Worksheets(1).cells(i,9).value=rs.fields(6).value
objexcelApp.Worksheets(1).cells(i,10).value=rs.fields(7).value
objexcelApp.Worksheets(1).cells(i,11).value=rs.fields(8).value
objexcelApp.Worksheets(1).cells(i,12).value=rs.fields(9).value
objexcelApp.Worksheets(1).cells(i,13).value=rs.fields(10).value
objexcelApp.Worksheets(1).cells(i,14).value=rs.fields(11).value
objexcelApp.Worksheets(1).cells(i,15).value=rs.fields(12).value
objexcelApp.Worksheets(1).cells(i,16).value=rs.fields(13).value
objexcelApp.Worksheets(1).cells(i,17).value=rs.fields(14).value
objexcelApp.Worksheets(1).cells(i,18).value=rs.fields(15).value
objexcelApp.Worksheets(1).cells(i,19).value=rs.fields(16).value
objexcelApp.Worksheets(1).cells(i,20).value=rs.fields(17).value
objexcelApp.Worksheets(1).cells(i,21).value=rs.fields(26).value
objexcelApp.Worksheets(1).cells(i,22).value=rs.fields(20).value
objexcelApp.Worksheets(1).cells(i,23).value=rs.fields(21).value
objexcelApp.Worksheets(1).cells(i,24).value=rs.fields(22).value
objexcelApp.Worksheets(1).cells(i,25).value=rs.fields(23).value
objexcelApp.Worksheets(1).cells(i,26).value=rs.fields(25).value
End With
End if
i=5
。。。。。。。。。。
。。。。。。。。。。
i=N
rs.close
cn.close
Set rs=Nothing
Set comm=Nothing
Set cn=Nothing
Set objexcelApp=Nothing
End Sub

管理员注:本帖已被纳入此次探讨发帖整理之方案汇总,请点此详阅
失去的是记忆,留下的依然是记忆
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32572条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。