Ecel宏读取Wincc变量记录_第1页
Ecel宏读取Wincc变量记录_第2页
Ecel宏读取Wincc变量记录_第3页
Ecel宏读取Wincc变量记录_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、利用 Excel 宏读取 Wincc 变量记录生成报表Dim sPro, sDsn, sSer, sCon, sSqlDim conn, oRs, oComDim DSNNameDim i As Integer Dim sStart, sStop As StringSub DTPFormat()日期控件显示格式Sheet1.DTPicker1.Format = dtpCustom Sheet1.DTPicker1.CustomFormat = yyyy-MM-dd hh:mm Sheet1.DTPicker1.Value = Now()Sheet1.DTPicker2.Format = dtp

2、Custom Sheet1.DTPicker2.CustomFormat = yyyy-MM-dd hh:mm Sheet1.DTPicker2.Value = Now()End SubSub get_wincc_data()-Get Database DSN nameSet DSNName = CreateObject(CCHMIRuntime.HMIRuntime) sDsn = DSNName.Tags(DatasourceNameRT).Read -build connection stringsPro = Provider=WinCCOLEDBProvider.1; sDsn = C

3、atalog= & sDsn & ; sSer = Data Source=.WinCC sCon = sPro & sDsn & sSerSet conn = CreateObject(ADODB.Connection) conn.ConnectionString = sCon conn.CursorLocation = 3 conn.OpenSet oRs = CreateObject(ADODB.Recordset)Set oCom = CreateObject(ADODB.Command) oCom.CommandType = 1Set oCom.ActiveConnection =

4、conn 查询启止时间sStart = Year(DTPicker1.Value) & - & Month(DTPicker1.Value) & - Day(DTPicker1.Value) & & Hour(DTPicker1.Value) & : & Minute(DTPicker1.Value)sStop = Year(DTPicker2.Value) & - & Month(DTPicker2.Value) & - Day(DTPicker2.Value) & & Hour(DTPicker2.Value) & : & Minute(DTPicker2.Value)转为 UTC 时间

5、sStart = DateAdd(h, -8, CDate(sStart) sStop = DateAdd(h, -8, CDate(sStop)读取 Fan1_T1sSql = Tag:R,(ProcessValueArchivestart_flag),& sStart & , & sStop & order by datetimeoCom.CommandText = sSqlSet oRs = oCom.ExecuteIf (oRs.EOF) ThenoRs.CloseElseoRs.MoveFirsti = 0Do While Not oRs.EOFDim start_timestart

6、_time = DateAdd(h, 8, CDate(oRs.fields(1)Sheet1.Cells(i + 3, 2) = start_time oRs.MoveNexti = i + 1Loop oRs.CloseEnd If读取 Fan1_T2sSql = Tag:R,(ProcessValueArchiveend_flag), & sStart & , & sStop & order by datetimeoCom.CommandText = sSqlSet oRs = oCom.ExecuteIf (oRs.EOF) ThenoRs.CloseElseoRs.MoveFirst

7、i = 0Do While Not oRs.EOFDim end_timeend_time = DateAdd(h, 8, CDate(oRs.fields(1)Sheet1.Cells(i + 3, 3) = end_time oRs.MoveNexti = i + 1Loop oRs.CloseEnd If读取 Fan1_P1sSql = Tag:R,(ProcessValueArchivereason_flag), & sStart & , & sStop & order by datetimeoCom.CommandText = sSqlSet oRs = oCom.ExecuteIf

8、 (oRs.EOF) ThenoRs.CloseElseoRs.MoveFirsti = 0Do While Not oRs.EOFDim manjuanmanjuan = oRs.fields(2).ValueIf manjuan = 20 ThenSheet1.Cells(i + 3, 4) = 是ElseSheet1.Cells(i + 3, 4) = 否End If oRs.MoveNexti = i + 1Loop oRs.CloseEnd If读取 Fan1_P2sSql = Tag:R,(ProcessValueArchivereason_flag), & sStart & ,

9、& sStop & order by datetimeoCom.CommandText = sSqlSet oRs = oCom.ExecuteIf (oRs.EOF) ThenoRs.CloseElseoRs.MoveFirsti = 0Do While Not oRs.EOFDim manjuan_flag manjuan_flag = oRs.fields(2).ValueIf manjuan_flag = 10 ThenSheet1.Cells(i + 3, 5) = 停车ElseIf manjuan_flag = 20 ThenSheet1.Cells(i + 5, 5) = 自动切

10、换ElseIf manjuan_flag = 30 ThenSheet1.Cells(i + 3, 5) = 手动切换End IfoRs.MoveNexti = i + 1Loop oRs.CloseEnd If读取 Fan1_P1sSql = Tag:R,(ProcessValueArchiveall_counter), & sStart & , & sStop & order by datetimeoCom.CommandText = sSqlSet oRs = oCom.ExecuteIf (oRs.EOF) ThenoRs.CloseElseoRs.MoveFirsti = 0Do W

11、hile Not oRs.EOFSheet1.Cells(i + 3, 6) = oRs.fields(2).Value oRs.MoveNexti = i + 1Loop oRs.CloseEnd If读取 Fan1_P1sSql = Tag:R,(ProcessValueArchiveok_counter), & sStart & , & sStop & order by datetimeoCom.CommandText = sSqlSet oRs = oCom.ExecuteIf (oRs.EOF) ThenoRs.CloseElseoRs.MoveFirsti = 0Do While Not oRs.EOFSheet1.Cells(i + 3, 7) = oRs.fields(2).Value oRs.MoveNexti = i + 1Loop oRs.CloseEnd IfSet oRs = NothingSet conn = NothingEnd SubPrivate Sub DTPicker1_Change()clear_cell 清除已经填充的数据 get_wincc_data 读取

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论