回复:在wincc中如何用Spreadsheet显示已建立的Excel

菜鸟先飞早入林

  • 帖子

    33
  • 精华

    0
  • 被关注

    17

论坛等级:游士

注册时间:2015-03-09

普通 普通 如何晋级?

发布于 2015-03-09 09:59:56

8楼

展开查看
以下是引用zhangli0在2014-10-16 08:46:49的发言 >5楼:wincc画面上Excel控件的名字为“控件1"
zhangli0按着这格式写了VB,但是EXCEL控件中还是未能显示数据,能帮忙看下问题出在哪吗,代码如下
Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)

'---------------------------------------
Dim con
Dim kongjian1
Set kongjian1 = ScreenItems("ribb")

Dim str
'Dim blnOK
Dim sql
Dim it
Dim i
Dim rst
Dim cmd
Dim obj
Dim ok
Dim worksheet

Dim qyear
Dim qmonth
Dim qday
Dim qhour
Dim qendyear
Dim qendmonth
Dim qendday
Dim qendhour

Dim reportname
reportname="日报表"


Dim t1,t2

On Error Resume Next

Set obj=hmiruntime.Screens("日报表").ScreenItems("ribb")

Set worksheet=obj.Object.sheets(1)


Set con=CreateObject("ADODB.Connection")

str="Provider=MSDASQL;DSN=yx;Uid=sa;Pwd=;"
con.ConnectionString=str
con.Open

If con.State=1 Then
Dim rili
Set rili=ScreenItems("rq1")

qyear=rili.year
qmonth=rili.month
qday=rili.day
qhour=rili.hour




if qmonth<10 then
if qday<10 then
t1=qyear & "-0" & qmonth & "-0" & qday
Else
t1=qyear & "-0" & qmonth & "-" & qday
End If
End If
If qmonth>=10 Then
If qday<10 Then
t1=qyear & "-" & qmonth & "-0" & qday

else
t1=qyear & "-" & qmonth & "-" & qday

End If
End If
Dim d1
Dim d2
d1=t1 & " 00" & ":00" & ":00"
d2=t1 & " 23" & ":59" & ":00"

sql="select * from dbo.日报表 where 时间>= '"&d1&"' and 时间<='"&d2&"' order by 时间 ASC"

Set cmd=CreateObject("ADODB.Command")
cmd.ActiveConnection=con
cmd.CommandText=sql
Set rst=CreateObject("ADODB.Recordset")
Set rst=cmd.Execute

With worksheet
.activate
i=4
If rst.RecordCount>2000 Then
ok=MsgBox("符合条件的记录超过2000条!",vbOK)

Else

Do Until rst.EOF

worksheet.cells(i,1).value=rst.fields("时间").value


i=i+1
rst.movenext
Loop
End If
End With
Set worksheet=Nothing
Set obj=Nothing
rst.close
Set rst=Nothing
Set cmd=Nothing
'MsgBox "执行成功",vbOKOnly,"提示"
con.Close
End If
Set con=Nothing
End Sub
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32979条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。