Jump to content
Sign in to follow this  
JeromeB

Export ListView in Excel

Recommended Posts

JeromeB

hey guys,

I have actually a form who generate a listview with 3 columns.

I would like to add a button, and when we click on it, the listview items are export in Excel.

Range by columns.

thx for your help.

Jérôme

Share this post


Link to post
Share on other sites
water

The Array UDF has function _ArrayDisplay which displays an array in a lsitview and lets you copy the content to the clipboard.

The Listview is copied to an array and then written to the clipboard. The example below is taken directly from arry.au3 and copies all selected listview entries to an array.

Local $aiCurItems[1] = [0]
For $i = 0 To GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMCOUNT, 0, 0)
 If GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMSTATE, $i, 0x2) Then
    $aiCurItems[0] += 1
    ReDim $aiCurItems[$aiCurItems[0] + 1]
    $aiCurItems[$aiCurItems[0]] = $i
 EndIf
Next

You could then use function _ExcelWriteArray to write the array to Excel.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
JeromeB

Hey

Thx for your answer, but i dont understand how to do for put my entire listview into an array.

I have actually

$List1 = GUICtrlCreateListView("", 9, 8, 615, 374)
_GUICtrlListView_AddColumn($List1, "IP", 100)
_GUICtrlListView_AddColumn($List1, "Computer Name", 100)
_GUICtrlListView_AddColumn($List1, "User Actually Connected", 200)

And adding items with

GUICtrlCreateListViewItem($IpList & "|" & $sResult & "|" & $user, $List1)

Can you give me an exemple to show me how to procede.

Jérôme

Edited by Jerome60

Share this post


Link to post
Share on other sites
water

Can you give me an exemple to show me how to procede.

Sure. Something like this:

#include <Guilistview.au3>
#include <excel.au3>
GUICreate("listview items", 220, 250, 100, 200)
$listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
GUISetState()
Sleep(2000)
$oExcel = _ExcelBookNew()
$iItems = _GUICtrlListView_GetItemCount($listview)
For $iItem = 0 To $iItems-1
    $Zf = _GUICtrlListView_GetItemTextString($listview, $iItem)
    $Zf = StringSplit($Zf, "|", 1)
    _ExcelWriteArray($oExcel, $iItem + 1, 1, $Zf, 0, 1)
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×