PLC论坛-全力打造可编程控制器专业技术论坛

 找回密码
 注册哦

QQ登录

只需一步,快速开始

快捷登录

查看: 1029|回复: 2

自己做的wincc报表vbs脚本

[复制链接]
发表于 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

回复

使用道具 举报

发表于 2013-4-21 11:09:08 | 显示全部楼层
好东西,我收藏下!另外,我用过WINCC调用SQLSERVER,基本思路和这个一样!~
回复 支持 反对

使用道具 举报

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

能否共享下  怎么调用sql
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册哦

本版积分规则

QQ|小黑屋|手机版|Archiver|PLC技术网-PLC论坛 ( 粤ICP备17165530号 )|网站地图

GMT+8, 2024-3-29 06:13 , Processed in 0.042577 second(s), 24 queries .

快速回复 返回顶部 返回列表