回复:Wincc结合Listview控件从SQL数据库查询完后怎么实现数据的打印?

随心。

  • 帖子

    3
  • 精华

    0
  • 被关注

    0

论坛等级:新手

注册时间:2010-03-12

普通 普通 如何晋级?

发布于 2010-03-14 00:53:11

2楼

谢谢斑竹,版竹的意思是要我换一种数据显示方式吧,从SQL里查数据,我只会用LISTVIEW显示。
我结合网上很多意见,把LISTVIEW显示的数据导到EXCEL里,然后进行打印,不知哪里有问题,只打印出了目录,没有数据。
下面是我的程序,请大家给指点一下:
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")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open ("d:\CANSHU.xls")



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 Each oItem In ListView1.ListItems

irow = irow + 1

xlSheet.Cells(irow + 2, 1).Value = oItem

xlSheet.Cells(irow + 2, 2).Value = oItem.SubItems(1)

xlSheet.Cells(irow + 2, 3).Value = oItem.SubItems(2)

xlSheet.Cells(irow + 2, 4).Value = oItem.SubItems(3)

xlSheet.Cells(irow + 2, 5).Value = oItem.SubItems(4)

xlSheet.Cells(irow + 2, 6).Value = oItem.SubItems(5)

Next


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
xlBook.Save
xlSheet.PrintOut
xlApp.QUIT
Set xlApp = Nothing '交还控制给Excel
Set xlBook = Nothing
Set xlSheet = Nothing
End With
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32575条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

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

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

  • 分享

  • 只看
    楼主

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