找回密码
 加入
搜索
查看: 5371|回复: 4

[GUI管理] 带分页(tab)的ListView导出到Excel

[复制链接]
发表于 2011-3-26 22:06:46 | 显示全部楼层 |阅读模式
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 444, 192, 124)
$Tab1 = GUICtrlCreateTab(32, 32, 545, 337)
$TabSheet1 = GUICtrlCreateTabItem("分页1")
$ListView1 = GUICtrlCreateListView("ID1|NAME1|OTHER1", 40, 64, 530, 294)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView1)
GUICtrlCreateListViewItem('2|李四|56454688', $ListView1)
GUICtrlCreateListViewItem('3|王五|86575765', $ListView1)
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView1)
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView1)
GUICtrlCreateListViewItem('6|成八|64651873', $ListView1)
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView1)
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView1)
$TabSheet2 = GUICtrlCreateTabItem("分页2")
$ListView2 = GUICtrlCreateListView("ID2|NAME2|OTHER2", 40, 64, 529, 297)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView2)
GUICtrlCreateListViewItem('2|李四|56454688', $ListView2)
GUICtrlCreateListViewItem('3|王五|86575765', $ListView2)
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView2)
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView2)
GUICtrlCreateListViewItem('6|成八|64651873', $ListView2)
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView2)
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView2)
GUICtrlCreateTabItem("")
$Button1 = GUICtrlCreateButton("to Excel", 40, 384, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd



请教 如何到出当前的分页中的ListView到 Excel?  包括ListView的表头 ID1|NAME1|OTHER1   谢谢大大们指教  

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-3-28 08:13:44 | 显示全部楼层
当前选择第  GUICtrlRead($Tab1) 页
发表于 2011-4-7 16:29:02 | 显示全部楼层
很好很好很给力啊
发表于 2011-4-8 14:02:16 | 显示全部楼层
#include <Excel.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Local $ListView[2], $Test[2] = ["ID1|NAME1|OTHER1", "ID2|NAME2|OTHER2"]
$Form1 = GUICreate("Form1", 623, 444, 192, 124)
$Tab1 = GUICtrlCreateTab(32, 32, 545, 337)
$TabSheet1 = GUICtrlCreateTabItem("分页1")
$ListView[0] = GUICtrlCreateListView($Test[0], 40, 64, 530, 294)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView[0])
GUICtrlCreateListViewItem('2|李四|56454688', $ListView[0])
GUICtrlCreateListViewItem('3|王五|86575765', $ListView[0])
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView[0])
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView[0])
GUICtrlCreateListViewItem('6|成八|64651873', $ListView[0])
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView[0])
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView[0])
$TabSheet2 = GUICtrlCreateTabItem("分页2")
$ListView[1] = GUICtrlCreateListView($Test[1], 40, 64, 529, 297)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView[1])
GUICtrlCreateListViewItem('2|李四|56454688', $ListView[1])
GUICtrlCreateListViewItem('3|王五|86575765', $ListView[1])
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView[1])
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView[1])
GUICtrlCreateListViewItem('6|成八|64651873', $ListView[1])
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView[1])
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView[1])
GUICtrlCreateTabItem("")
$Button1 = GUICtrlCreateButton("to Excel", 40, 384, 75, 25)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        Local $array[1]
                        For $i = 0 To UBound($ListView) - 1
                                $Count = _GUICtrlListView_GetItemCount($ListView[$i])
                                _ArrayAdd($array, $Test[$i])
                                If $Count <> 0 Then
                                        For $ii = 0 To $Count - 1
                                                _ArrayAdd($array, _GUICtrlListView_GetItemTextString($ListView[$i], $ii))
                                        Next
                                EndIf
                        Next
                        $excel = _ExcelBookNew(1)
                        For $i = 1 To UBound($array) - 1
                                $htest = StringSplit($array[$i], "|")
                                For $ii = 0 To $htest[0]
                                        _ExcelWriteCell($excel, $htest[$ii], $i, $ii)
                                Next
                        Next
        EndSwitch
WEnd
发表于 2011-4-8 14:02:22 | 显示全部楼层
#include <Excel.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Local $ListView[2], $Test[2] = ["ID1|NAME1|OTHER1", "ID2|NAME2|OTHER2"]
$Form1 = GUICreate("Form1", 623, 444, 192, 124)
$Tab1 = GUICtrlCreateTab(32, 32, 545, 337)
$TabSheet1 = GUICtrlCreateTabItem("分页1")
$ListView[0] = GUICtrlCreateListView($Test[0], 40, 64, 530, 294)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView[0])
GUICtrlCreateListViewItem('2|李四|56454688', $ListView[0])
GUICtrlCreateListViewItem('3|王五|86575765', $ListView[0])
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView[0])
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView[0])
GUICtrlCreateListViewItem('6|成八|64651873', $ListView[0])
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView[0])
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView[0])
$TabSheet2 = GUICtrlCreateTabItem("分页2")
$ListView[1] = GUICtrlCreateListView($Test[1], 40, 64, 529, 297)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView[1])
GUICtrlCreateListViewItem('2|李四|56454688', $ListView[1])
GUICtrlCreateListViewItem('3|王五|86575765', $ListView[1])
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView[1])
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView[1])
GUICtrlCreateListViewItem('6|成八|64651873', $ListView[1])
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView[1])
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView[1])
GUICtrlCreateTabItem("")
$Button1 = GUICtrlCreateButton("to Excel", 40, 384, 75, 25)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        Local $array[1]
                        For $i = 0 To UBound($ListView) - 1
                                $Count = _GUICtrlListView_GetItemCount($ListView[$i])
                                _ArrayAdd($array, $Test[$i])
                                If $Count <> 0 Then
                                        For $ii = 0 To $Count - 1
                                                _ArrayAdd($array, _GUICtrlListView_GetItemTextString($ListView[$i], $ii))
                                        Next
                                EndIf
                        Next
                        $excel = _ExcelBookNew(1)
                        For $i = 1 To UBound($array) - 1
                                $htest = StringSplit($array[$i], "|")
                                For $ii = 0 To $htest[0]
                                        _ExcelWriteCell($excel, $htest[$ii], $i, $ii)
                                Next
                        Next
        EndSwitch
WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-11 04:58 , Processed in 0.096148 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表