请教问题:附脚本,Wincc中SQL数据读取到listview,然后将listview数据写入Excel中

已锁定

郑州代工

  • 帖子

    30
  • 精华

    0
  • 被关注

    4

论坛等级:游侠

注册时间:2008-09-11

普通 普通 如何晋级?

请教问题:附脚本,Wincc中SQL数据读取到listview,然后将listview数据写入Excel中

5354

12

2008-09-11 09:32:03

已经成功的将数据写入到listview,在VB中做实验数据能够从listview数据写入Excel中,但是在VB中就是不能读数据,那位大侠指点一下。
通过调试发现错误的地方在这里,ListView1.ListItems(irow)这条语句不能从ListView1中读取数据,Scrip Debugger显示 读取的数据error
脚本如下

Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)
On Error Resume Next
Dim irow, icol
Dim xlApp 'As Excel.Application
Dim xlBook 'As Excel.Workbook
Dim xlSheet 'As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
Dim ListView1
Set ListView1=ScreenItems("ListView1")
With ListView1
If MsgBox("您真的要将资料导出到EXCEL中吗?", vbExclamation + vbYesNo, "警告") = vbYes Then
If .ListItems.Count > 0 Then
MsgBox "&ListView1.ListItems.Count&"
xlSheet.Cells(1, 2) = "温湿度数据Excel报表"
xlApp.Range("A1:F1").MergeCells = True
xlApp.Range("A1:F1").HorizontalAlignment = xlCenter
xlSheet.Columns(1).ColumnWidth = 18
xlSheet.Cells(2, 1) = "时间"
xlSheet.Cells(2, 2) = "标签1"
xlSheet.Cells(2, 3) = "标签2"
xlSheet.Cells(2, 4) = "标签3"
xlSheet.Cells(2, 5) = "标签4"
xlSheet.Cells(2, 6) = "标签5"
For irow = 1 To .ListItems.Count
xlSheet.Cells(irow + 2, 1).Value = .ListItems(irow)
xlSheet.Cells(irow + 2, 2).Value = .ListItems(irow).SubItems(1)
xlSheet.Cells(irow + 2, 3).Value = .ListItems(irow).SubItems(2)
xlSheet.Cells(irow + 2, 4).Value = .ListItems(irow).SubItems(3)
xlSheet.Cells(irow + 2, 5).Value = .ListItems(irow).SubItems(4)
xlSheet.Cells(irow + 2, 6).Value = .ListItems(irow).SubItems(5)
Next 'irow
xlApp.Range("A2:F2").Columns.Interior.ColorIndex = 40
xlApp.Range("A2:F2").Borders.LineStyle = xlContinuous
xlApp.Visible = True
xlApp.Range(xlSheet.Cells(2 + .ListItems.Count + 1, 1), xlSheet.Cells(2 + .ListItems.Count + 1, 4)).Columns.Interior.ColorIndex = 40
xlApp.Range(xlSheet.Cells(2 + .ListItems.Count + 1, 1), xlSheet.Cells(2 + .ListItems.Count + 1, 4)).Borders.LineStyle = xlContinuous
Else
MsgBox "*******!", vbExclamation + vbOKOnly, "警告"
End If
Else
End If
xlApp.QUIT
Set xlApp = Nothing '交还控制给Excel
Set xlBook = Nothing
Set xlSheet = Nothing
End With



End Sub
请教问题:附脚本,Wincc中SQL数据读取到listview,然后将listview数据写入Excel中 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32566条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

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

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

  • 分享

  • 只看
    楼主

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