回复:listview 打印

小仙女

  • 帖子

    23
  • 精华

    0
  • 被关注

    0

论坛等级:新手

注册时间:2008-10-06

普通 普通 如何晋级?

发布于 2008-10-24 09:58:25

0楼

dcount107大哥;我用你给的那个贴子上的代码写;怎么数据写不到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")

Set xlBook = xlApp.Workbooks.Add

Set xlSheet = xlBook.Worksheets(1)

Dim ListView1

Set ListView1=ScreenItems("ListTable")

With ListView1

If MsgBox("您真的要将资料导出到EXCEL中吗?", vbExclamation + vbYesNo, "警告") = vbYes Then

If .ListItems.Count > 0 Then

MsgBox "确定导入Excel吗?"

xlSheet.Cells(1, 2) = " 三角阀密封性检测数据Excel报表"

xlApp.Range("A1:H1").MergeCells = True

xlApp.Range("A1:H1").HorizontalAlignment = xlCenter

xlSheet.Columns(1).ColumnWidth = 18
xlSheet.Columns(2).ColumnWidth = 18
xlSheet.Columns(3).ColumnWidth = 18
xlSheet.Columns(4).ColumnWidth = 18
xlSheet.Columns(5).ColumnWidth = 18
xlSheet.Columns(6).ColumnWidth = 18
xlSheet.Columns(7).ColumnWidth = 18
xlSheet.Columns(8).ColumnWidth = 18

xlSheet.Cells(2, 1) = "ID"

xlSheet.Cells(2, 2) = "测试序列号"

xlSheet.Cells(2, 3) = "产品序列号"

xlSheet.Cells(2, 4) = "测试状态"

xlSheet.Cells(2, 5) = "初始压力"

xlSheet.Cells(2, 6) = "终止压力"

xlSheet.Cells(2, 7) = "错误代码"

xlSheet.Cells(2, 8) = "测试时间"

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)

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

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

Next



xlApp.Range("A2:H2").Columns.Interior.ColorIndex = 40

xlApp.Range("A2:H2").Borders.LineStyle = xlContinuous

xlApp.Visible = True

xlApp.Range(xlSheet.Cells(2 + ListView1.ListItems.Count + 1, 1), xlSheet.Cells(2 + ListView1.ListItems.Count + 1, 4)).Columns.Interior.ColorIndex = 40

xlApp.Range(xlSheet.Cells(2 + ListView1.ListItems.Count + 1, 1), xlSheet.Cells(2 + ListView1.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
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32760条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

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

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

  • 分享

  • 只看
    楼主

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