自己做的wincc报表vbs脚本

[复制链接]
查看1093 | 回复2 | 2013-4-18 14:00:43 | 显示全部楼层 |阅读模式
西门子官方论坛上做报表的大神有很多,但总结一下,有两种主流模式,一种是利用脚本读取sql,一中是用vbs做脚本触发,定时向excel写数据,有人本人对sql一窍不通,选择后者,水平有限经供参考,也请论坛大神多指点指点

Dim q
Set q = HMIRuntime.Tags("q")
HMIRuntime.Trace"Value:" &q.Read(1)&vbCrLf

Dim p
Set p = HMIRuntime.Tags("p")
HMIRuntime.Trace"Value:" &p.Read(1)&vbCrLf

Dim t
Set t = HMIRuntime.Tags("t")
HMIRuntime.Trace"Value:" &t.Read(1)&vbCrLf

Dim ch4
Set ch4 = HMIRuntime.Tags("ch4")
HMIRuntime.Trace"Value:" &ch4.Read(1)&vbCrLf

Dim co
Set co = HMIRuntime.Tags("co")
HMIRuntime.Trace"Value:" &co.Read(1)&vbCrLf

Dim sysYear
Set sysYear = HMIRuntime.Tags("sysYear")
HMIRuntime.Trace"Value:" &sysYear.Read(1)&vbCrLf

Dim sysMonth
Set sysMonth = HMIRuntime.Tags("sysMonth")
HMIRuntime.Trace"Value:" &sysMonth.Read(1)&vbCrLf

Dim sysDay
Set sysDay = HMIRuntime.Tags("sysDay")
HMIRuntime.Trace"Value:" &sysDay.Read(1)&vbCrLf

Dim sysHour
Set sysHour = HMIRuntime.Tags("sysHour")
HMIRuntime.Trace"Value:" &sysHour.Read(1)&vbCrLf

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim fso, f, fc, nf,fso1
Dim path,folderName
  path="E:\报表\日报表"
  folderName=CStr(sysYear.value)+"年"+CStr(sysMonth.value)+"月抽放报表"

    Set fso = CreateObject("scripting.FileSystemObject")
    Set f = fso.GetFolder(path)
    Set fso1= CreateObject("scripting.FileSystemObject")
    Set fc=f.SubFolders

    If Not (fso1.FolderExists(path&"\"&folderName)) Then

    Set nf = fc.Add(folderName)

   End If

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim name1
name1=path+folderName+"\"+CStr(sysYear.value)+"-"+CStr(sysMonth.value)+"-"+CStr(sysDay.value)+"日报表.xls"


Dim ob,h
h = sysHour.value
set ob = creatobject("excel.application")
ob.visible = False
ob.workbooks.open"E:\报表\模板\日报表.xls"

dim i,j
with ob
if h = 0 then
  .cells(2,8).value = null
for i = 6 to 29
for j = 2 to 8
  .cells(i,j).value = null
next
next

end if

if h < 23 then
i = h + 6
.cells(i,2).value = ch4.value
.cells(i,3).value = co.value
.cells(i,4).value = t.value
.cells(i,5).value = p.value
.cells(i,6).value = q.value

else if h = 23
.cells(2,8).value = CStr(sysYear.value)+"-"+CStr(sysMonth.value)+"-"+CStr(sysDay.value)
.cells(29,2).value = ch4.value
.cells(29,3).value = co.value
.cells(29,4).value = t.value
.cells(29,5).value = p.value
.cells(29,6).value = q.value

.activeworkbook.saveas name1
Else
.activeworkbook.save
End If
End If
.activeworkbook.close
.quit
End With
Set ob =Nothing

End sub



月报表和这个差不多 只是多了个闰年平年判断和大小月,2月的判断,有兴趣共同讨论的可以q我11219082

kakalu | 2013-4-21 11:09:08 | 显示全部楼层
好东西,我收藏下!另外,我用过WINCC调用SQLSERVER,基本思路和这个一样!~
吉巴藤 | 2013-4-23 22:36:40 | 显示全部楼层
kakalu 发表于 2013-4-21 11:09
好东西,我收藏下!另外,我用过WINCC调用SQLSERVER,基本思路和这个一样!~

能否共享下  怎么调用sql
您需要登录后才可以回帖 登录 | 注册哦

本版积分规则