带分页(tab)的ListView导出到Excel
#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 谢谢大大们指教 当前选择第GUICtrlRead($Tab1) 页 很好很好很给力啊 #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, $Test = ["ID1|NAME1|OTHER1", "ID2|NAME2|OTHER2"]
$Form1 = GUICreate("Form1", 623, 444, 192, 124)
$Tab1 = GUICtrlCreateTab(32, 32, 545, 337)
$TabSheet1 = GUICtrlCreateTabItem("分页1")
$ListView = GUICtrlCreateListView($Test, 40, 64, 530, 294)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView)
GUICtrlCreateListViewItem('2|李四|56454688', $ListView)
GUICtrlCreateListViewItem('3|王五|86575765', $ListView)
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView)
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView)
GUICtrlCreateListViewItem('6|成八|64651873', $ListView)
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView)
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView)
$TabSheet2 = GUICtrlCreateTabItem("分页2")
$ListView = GUICtrlCreateListView($Test, 40, 64, 529, 297)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView)
GUICtrlCreateListViewItem('2|李四|56454688', $ListView)
GUICtrlCreateListViewItem('3|王五|86575765', $ListView)
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView)
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView)
GUICtrlCreateListViewItem('6|成八|64651873', $ListView)
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView)
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView)
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
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
_ExcelWriteCell($excel, $htest[$ii], $i, $ii)
Next
Next
EndSwitch
WEnd #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, $Test = ["ID1|NAME1|OTHER1", "ID2|NAME2|OTHER2"]
$Form1 = GUICreate("Form1", 623, 444, 192, 124)
$Tab1 = GUICtrlCreateTab(32, 32, 545, 337)
$TabSheet1 = GUICtrlCreateTabItem("分页1")
$ListView = GUICtrlCreateListView($Test, 40, 64, 530, 294)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView)
GUICtrlCreateListViewItem('2|李四|56454688', $ListView)
GUICtrlCreateListViewItem('3|王五|86575765', $ListView)
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView)
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView)
GUICtrlCreateListViewItem('6|成八|64651873', $ListView)
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView)
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView)
$TabSheet2 = GUICtrlCreateTabItem("分页2")
$ListView = GUICtrlCreateListView($Test, 40, 64, 529, 297)
GUICtrlCreateListViewItem('1|张三|65786315', $ListView)
GUICtrlCreateListViewItem('2|李四|56454688', $ListView)
GUICtrlCreateListViewItem('3|王五|86575765', $ListView)
GUICtrlCreateListViewItem('4|孙六|87654832', $ListView)
GUICtrlCreateListViewItem('5|赵七|96325478', $ListView)
GUICtrlCreateListViewItem('6|成八|64651873', $ListView)
GUICtrlCreateListViewItem('7|冯九|96437251', $ListView)
GUICtrlCreateListViewItem('8|钱十|64976835', $ListView)
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
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
_ExcelWriteCell($excel, $htest[$ii], $i, $ii)
Next
Next
EndSwitch
WEnd
页:
[1]