wincc报表例子vb
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
用VBS脚本实现,就是把文件名称以变量的形式表示。参考
'关闭保存
Dim patch,filename
filename=CStr(Year(Now))&CStr(Month(Now))&CStr(Day(Now))&CStr(Hour(N ow))+CStr(Minute(Now))&CStr(Second(Now))
patch= "d:\"&filename&"demo.xls"
objExcelApp.ActiveWorkbook.SaveAs patch
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp= Nothing
对于Excel报表,用VBS最灵活,Excel定义好格式后wincc来填空,平均累计值就用Excel的功能。
Dim excelapp
Dim aa,bb,cc
Set excelapp = CreateObject("Excel.Application")
Set aa = HMIRuntime.tags("tag1")
excelapp.visible = False'True
excelapp.workbooks.open "D:\excel.xls"
bb = Now 'getcurrent_datetime()
aa.Read
MsgBox CStr(bb)
excelapp.cells(1,1).value = "rrrrrr"'111111
excelapp.cells(1,2).value = CStr(bb)
excelapp.cells(2,2).value = CStr(aa.value)
excelapp.cells(3,2).value = CInt(aa.value)
excelapp.cells(4,2).value = CSng(aa.value)
excelapp.cells(5,2).value = CDbl(aa.value)
excelapp.cells(6,2).value = CLng(aa.value)
excelapp.cells(3,3).value = ScreenItems("33").outputvalue
excelapp.cells(4,4).value = ScreenItems("35").outputvalue
cc = "D:\excel" + Mid(CStr(bb), 1, 4)+ Mid(CStr(bb), 6, 2)+ Mid(CStr(bb), 9, 2) + Mid(CStr(bb), 12, 2)+ Mid(CStr(bb), 15, 2)+ Mid(CStr(bb), 18, 2) + ".xls" MsgBox cc
excelapp.DisplayAlerts = False '对打开的文件,直接保存时,避免弹出对话框窗口,而是直接覆盖
excelapp.activeworkbook.saveas cc '根据当前日期时间,另存为新的文件
'excelapp.activeworkbook.save ’对打开的文件,直接保存
'excelapp.activeworkbook.saveAs "D:\excelcopy.xls" ’直接另存为新的文件excelapp.workbooks.close
excelapp.quit
Set excelapp = Nothing
第一段:
Option Explicit
Function action
Dim fso,myfile,daystr,dstr,fname
dstr = FormatDateTime(Date)
fname="d:\" + dstr + ".xls"
Set fso = CreateObject("s cripting.FileSystemObject")
Set MyFile = fso.GetFile("d:\ExcelExample.xls")
MyFile.Copy (fname)
End Function
第二段:
Option Explicit
Function action
Dim fso,myfilep,daystr,dstr,fname
Set fso = CreateObject("s cripting.FileSystemObject")
dstr = FormatDateTime(Date)
HMIRuntime.Tags("i").write fso.GetAbsolutePathName("")
fname=HMIRuntime.ActiveProject.Path++dstr+.xls
Dim ObjExcelApp
Set objExcelApp = CreateObject("Excel.Application")
objExCelApp.Visible = True
objExcelApp.Workbooks.Open fname
Dim i
i=1
Do While objExcelApp.worksheets ("sheet1").Cells(i, 1).VAlue<>""
i=i+1
Loop
objExcelApp.worksheets ("sheet1").Cells(i, 2).VAlue = HMIRuntime.Tags("I-COD").read objExcelApp.worksheets ("sheet1").Cells(i, 3).VAlue = HMIRuntime.Tags("I-SS").read
objExcelApp.worksheets ("sheet1").Cells(i, 4).VAlue = HMIRuntime.Tags("I-PH").read
objExcelApp.worksheets ("sheet1").Cells(i, 5).VAlue = HMIRuntime.Tags("I-F").read
objExcelApp.worksheets ("sheet1").Cells(i, 6).VAlue = HMIRuntime.Tags("I-FI").read
objExcelApp.worksheets ("sheet1").Cells(i, 7).VAlue = HMIRuntime.Tags("O-COD").read objExcelApp.worksheets ("sheet1").Cells(i, 8).VAlue = HMIRuntime.Tags("O-SS").read
objExcelApp.worksheets ("sheet1").Cells(i, 9).VAlue = HMIRuntime.Tags("O-NH4N").read objExcelApp.worksheets ("sheet1").Cells(i, 10).VAlue = HMIRuntime.Tags("0-P").read