Function without Array:
; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #FUNCTION# ========================================================================================================= ; Name...........: _GUICtrlListView_SaveTxt() ; Description ...: Exports the details of a ListView to a .txt file. ; Syntax.........: _GUICtrlListView_SaveTxt($hListView, $sFile, [$sDelimiter = "|"]) ; Parameters ....: $hListView - Handle of the ListView. ; $sFile - FilePath, this should ideally use the filetype .txt e.g. @ScriptDir & "\Example.txt" ; $sDelimiter - [Optional] Delimiter to be used for the txt file. [Default = |] ; Requirement(s).: v3.2.12.1 or higher ; Return values .: Success - Returns filepath. ; Failure - Returns filepath & sets @error = 1 ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _GUICtrlListView_SaveTxt($hListView, $sFile, $sDelimiter = "|") Local $hFileOpen, $iError = 0, $sItem, $sString Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView) Local $iItemCount = _GUICtrlListView_GetItemCount($hListView) For $A = 0 To $iItemCount - 1 For $B = 0 To $iColumnCount - 1 $sItem = _GUICtrlListView_GetItemText($hListView, $A, $B) $sString &= $sItem If $B < $iColumnCount - 1 Then $sString &= $sDelimiter EndIf Next $sString &= @CRLF Next $hFileOpen = FileOpen($sFile, 2) FileWrite($hFileOpen, $sString) FileClose($hFileOpen) If @error Then $iError = 1 EndIf Return SetError($iError, 0, $sFile) EndFunc ;==>_GUICtrlListView_SaveTxt
Function with Array: - It uses another Function of mine called _GUICtrlListView_CreateArray()
; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #FUNCTION# ========================================================================================================= ; Name...........: _GUICtrlListView_SaveTxt() ; Description ...: Exports the details of a ListView to a .txt file. ; Syntax.........: _GUICtrlListView_SaveTxt($aArray, $sFile, [$sDelimiter = "|"]) ; Parameters ....: $aArray - Array returned from _GUICtrlListView_CreateArray() ; $sFile - FilePath, this should ideally use the filetype .txt e.g. @ScriptDir & "\Example.txt" ; $sDelimiter - [Optional] Delimiter to be used for the txt file. [Default = |] ; Requirement(s).: v3.2.12.1 or higher ; Return values .: Success - Returns filepath. ; Failure - Returns filepath & sets @error = 1 ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _GUICtrlListView_SaveTxt($aArray, $sFile, $sDelimiter = "|") Local $hFileOpen, $iError = 0, $sItem, $sString For $A = 1 To $aArray[0][0] For $B = 0 To $aArray[0][1] - 1 $sItem = $aArray[$A][$B] $sString &= $sItem If $B < $aArray[0][1] - 1 Then $sString &= $sDelimiter EndIf Next $sString &= @CRLF Next $hFileOpen = FileOpen($sFile, 2) FileWrite($hFileOpen, $sString) FileClose($hFileOpen) If @error Then $iError = 1 EndIf Return SetError($iError, 0, $sFile) EndFunc ;==>_GUICtrlListView_SaveTxt
Example use of Function without Array:
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> _Main() Func _Main() Local $hListView, $iButton, $iListView, $sPrintOut GUICreate("_GUICtrlListView_SaveTxt()", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX)) $iListView = GUICtrlCreateListView("", 0, 0, 400, 270) $hListView = GUICtrlGetHandle($iListView) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) $iButton = GUICtrlCreateButton("Export Txt", 400 - 80, 275, 75, 22.5) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM) GUISetState(@SW_SHOW) __ListViewFill($hListView, Random(1, 5, 1), Random(25, 100, 1)) ; Fill the ListView with Random data. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iButton $sPrintOut = _GUICtrlListView_SaveTxt($hListView, @ScriptDir & "\Export.txt") ShellExecute($sPrintOut) EndSwitch WEnd EndFunc ;==>_Main ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #FUNCTION# ========================================================================================================= ; Name...........: _GUICtrlListView_SaveTxt() ; Description ...: Exports the details of a ListView to a .txt file. ; Syntax.........: _GUICtrlListView_SaveTxt($hListView, $sFile, [$sDelimiter = "|"]) ; Parameters ....: $hListView - Handle of the ListView. ; $sFile - FilePath, this should ideally use the filetype .txt e.g. @ScriptDir & "\Example.txt" ; $sDelimiter - [Optional] Delimiter to be used for the txt file. [Default = |] ; Requirement(s).: v3.2.12.1 or higher ; Return values .: Success - Returns filepath. ; Failure - Returns filepath & sets @error = 1 ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _GUICtrlListView_SaveTxt($hListView, $sFile, $sDelimiter = "|") Local $hFileOpen, $iError = 0, $sItem, $sString Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView) Local $iItemCount = _GUICtrlListView_GetItemCount($hListView) For $A = 0 To $iItemCount - 1 For $B = 0 To $iColumnCount - 1 $sItem = _GUICtrlListView_GetItemText($hListView, $A, $B) $sString &= $sItem If $B < $iColumnCount - 1 Then $sString &= $sDelimiter EndIf Next $sString &= @CRLF Next $hFileOpen = FileOpen($sFile, 2) FileWrite($hFileOpen, $sString) FileClose($hFileOpen) If @error Then $iError = 1 EndIf Return SetError($iError, 0, $sFile) EndFunc ;==>_GUICtrlListView_SaveTxt Func __ListViewFill($hListView, $iColumns, $iRows) ; Required only for _Main(), but not the UDF! For $A = 0 To $iColumns - 1 _GUICtrlListView_InsertColumn($hListView, $A, "Column " & $A + 1, 50) _GUICtrlListView_SetColumnWidth($hListView, $A - 1, -2) Next For $A = 0 To $iRows - 1 _GUICtrlListView_AddItem($hListView, Chr(Random(65, 90, 1)) & " - Row " & $A + 1 & ": Col 1", $A) For $B = 1 To $iColumns _GUICtrlListView_AddSubItem($hListView, $A, "Row " & $A + 1 & ": Col " & $B + 1, $B) Next Next EndFunc ;==>__ListViewFill
Download the ZIP file to obtain all exporting Examples.
ListView Export.zip 19.96K
747 downloadsOther Examples for exporting ListView data are: _GUICtrlListView_SaveCSV(), _GUICtrlListView_SaveHTML() & _GUICtrlListView_SaveXML()
Edited by guinness, 30 August 2011 - 05:45 AM.




