本回答有11位钻石用户推荐
回答者:
zhangli0 - 超级顾问  第15级
-07-25 16:40:06
''当前为按钮触发,
''创建一张当前日期命名的表格,如存在,跳过
Dimfso,myfile,daystr,dstr,fname
dstr=CStr(Year(Now))&"-"&CStr(Month(Now))&"-"&CStr(Day(Now))
fname="E:\报表\"+dstr+".xls"
Setfso=CreateObject("scripting.FileSystemObject")
SetMyFile=fso.GetFile("E:\模板excel.xls")
Iffso.FileExists(fname)Then
''MsgBox"文件已经存在"
''文件存在,不执行
else
MyFile.Copy(fname)''''不存在,复制模板
EndIf
''检测当前日期名表格是否打开,如有,关闭保存
''模板是否打开状态,无需检测(copy)
DimobjExcelApp,objExcelBook,objExcelSheet
OnErrorResumeNext
DimExcelApp,ExcelBook
SetExcelApp=GetObject(,"Excel.Application")
IfTypeName(ExcleApp)="Application"Then
ForEachExcelBookInExcelApp.WorkBooks
IfExcelBook.FullName="E:\报表\"+dstr+".xls"Then
ExcelApp.ActiveWorkbook.Save
ExcelApp.Workbooks.Close
ExcelApp.Quit
SetExcelApp=Nothing
ExitFor
EndIf
Next
EndIf
''定义变量
''DimobjExcelApp
Dimtagtag1,tagtag2,tagtag3,tagtag4,tagtag5,tagtag6,tagtag7,tagtag8,tagtag9,tagtag10,tagtag11,tagtag12,tagtag13
Dimi,j,xuhao
Dimtagshijian,sheetname
''REPORT1.NO1~NO13需要记录的数据
Settagtag1=HMIRuntime.Tags("REPORT1.NO1")
Settagtag2=HMIRuntime.Tags("REPORT1.NO2")
Settagtag3=HMIRuntime.Tags("REPORT1.NO3")
Settagtag4=HMIRuntime.Tags("REPORT1.NO4")
Settagtag5=HMIRuntime.Tags("REPORT1.NO5")
Setxuhao=HMIRuntime.Tags("REPORT1_TR2")
sheetname="1#机当日批次报表"
''打开表格
SetobjExcelApp=CreateObject("Excel.Application")
''openfile
objExcelApp.Visible=True
objExcelApp.Workbooks.Open"E:\报表\"+dstr+".xls"
objExcelApp.Worksheets(sheetname).Activate
''实时数据写入
xuhao.Read
i=xuhao.Value+2
xuhao.Read
objExcelApp.Worksheets(sheetname).cells(i,1).value=xuhao.Value
tagshijian=CStr(Hour(Now))&":"&CStr(Minute(Now))&":"&CStr(Second(Now))
objExcelApp.Worksheets(sheetname).cells(i,2).value=tagshijian
tagtag1.Read
objExcelApp.Worksheets(sheetname).cells(i,3).value=tagtag1.Value
tagtag2.Read
objExcelApp.Worksheets(sheetname).cells(i,4).value=tagtag2.Value
tagtag3.Read
objExcelApp.Worksheets(sheetname).cells(i,5).value=tagtag3.Value
tagtag4.Read
objExcelApp.Worksheets(sheetname).cells(i,6).value=tagtag4.Value
tagtag5.Read
objExcelApp.Worksheets(sheetname).cells(i,7).value=tagtag5.Value
''关闭保存
objExcelApp.ActiveWorkbook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
SetobjExcelApp=Nothing
EndSub
本回答有17位钻石用户推荐
回答者:
泽诗冯冯 - 中级技术员  第6级
-07-25 22:22:01
上一页
1
下一页
如果觉得《wincc连接mysql数据库案例_WINCC读写SQL数据库的例子-工业支持中心-西门子中国》对你有帮助,请点赞、收藏,并留下你的观点哦!