Jump to content

A listview of the current tab in the export data to excel


 Share

Recommended Posts

#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("tab1")
$ListView1 = GUICtrlCreateListView("ID1|NAME1|OTHER1", 40, 64, 530, 294)
GUICtrlCreateListViewItem('1|a|65786315', $ListView1)
GUICtrlCreateListViewItem('2|b|56454688', $ListView1)
GUICtrlCreateListViewItem('3|c|86575765', $ListView1)
GUICtrlCreateListViewItem('4|d|87654832', $ListView1)
GUICtrlCreateListViewItem('5|e|96325478', $ListView1)
GUICtrlCreateListViewItem('6|f|64651873', $ListView1)
GUICtrlCreateListViewItem('7|g|96437251', $ListView1)
GUICtrlCreateListViewItem('8|h|64976835', $ListView1)
$TabSheet2 = GUICtrlCreateTabItem("tab2")
$ListView2 = GUICtrlCreateListView("ID2|NAME2|OTHER2", 40, 64, 529, 297)
GUICtrlCreateListViewItem('1|aa|6aasdx123', $ListView2)
GUICtrlCreateListViewItem('2|bb|5bbsdx123', $ListView2)
GUICtrlCreateListViewItem('3|cc|8ccsdx123', $ListView2)
GUICtrlCreateListViewItem('4|dd|8ddsdx123', $ListView2)
GUICtrlCreateListViewItem('5|ee|9eesdx123', $ListView2)
GUICtrlCreateListViewItem('6|ff|6ffsdx123', $ListView2)
GUICtrlCreateListViewItem('7|gg|9ggsdx123', $ListView2)
GUICtrlCreateListViewItem('8|hh|6hhsdx123', $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

A listview of the current tab in the export data to excel

how export to excel

Link to comment
Share on other sites

Hi i think the best way is to get the LV into an Array and then using _ExcelWriteArray to your Excelsheet:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#include <array.au3>

#Region ### START Koda GUI section ### Form=
Global $ListView[2]
$Form1 = GUICreate("Form1", 623, 444, 192, 124)
$Tab1 = GUICtrlCreateTab(32, 32, 545, 337)
$TabSheet1 = GUICtrlCreateTabItem("tab1")
$ListView[0] = GUICtrlCreateListView("ID1|NAME1|OTHER1", 40, 64, 530, 294)
ConsoleWrite("0: " & $ListView[0] & @CRLF)
GUICtrlCreateListViewItem('1|a|65786315', $ListView[0])
GUICtrlCreateListViewItem('2|b|56454688', $ListView[0])
GUICtrlCreateListViewItem('3|c|86575765', $ListView[0])
GUICtrlCreateListViewItem('4|d|87654832', $ListView[0])
GUICtrlCreateListViewItem('5|e|96325478', $ListView[0])
GUICtrlCreateListViewItem('6|f|64651873', $ListView[0])
GUICtrlCreateListViewItem('7|g|96437251', $ListView[0])
GUICtrlCreateListViewItem('8|h|64976835', $ListView[0])
$TabSheet2 = GUICtrlCreateTabItem("tab2")
$ListView[1] = GUICtrlCreateListView("ID2|NAME2|OTHER2", 40, 64, 529, 297)
ConsoleWrite("1: " & $ListView[1] & @CRLF)
GUICtrlCreateListViewItem('1|aa|6aasdx123', $ListView[1])
GUICtrlCreateListViewItem('2|bb|5bbsdx123', $ListView[1])
GUICtrlCreateListViewItem('3|cc|8ccsdx123', $ListView[1])
GUICtrlCreateListViewItem('4|dd|8ddsdx123', $ListView[1])
GUICtrlCreateListViewItem('5|ee|9eesdx123', $ListView[1])
GUICtrlCreateListViewItem('6|ff|6ffsdx123', $ListView[1])
GUICtrlCreateListViewItem('7|gg|9ggsdx123', $ListView[1])
GUICtrlCreateListViewItem('8|hh|6hhsdx123', $ListView[1])
GUICtrlCreateTabItem("")
$Button1 = GUICtrlCreateButton("to Excel", 40, 384, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$iActiveTab = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Tab1
            $iActiveTab =GUICtrlRead($Tab1)
        Case $Button1
            _ToExcel($ListView[$iActiveTab])
    EndSwitch
WEnd

Func _ToExcel($idListView)
    Local $hListView = GUICtrlGetHandle($idListView)
    Local $iItemCount = _GUICtrlListView_GetItemCount($hListView)
    Local $aSplit = _GUICtrlListView_GetItemTextArray($hListView)
    Local $iColCount = $aSplit[0]
    Local $aToExcel[$iItemCount][$iColCount]
    For $i = 0 to $iItemCount-1
        $aSplit = _GUICtrlListView_GetItemTextArray($hListView,$i)
        for $j = 1 to $iColCount
            $aToExcel[$i][$j-1] = $aSplit[$j]
        Next
    Next
    _ArrayDisplay($aToExcel)
    ;and here you have to insert your execlroutine _ExcelWriteArray ;sorry I have no Excel installed
EndFunc

mfg autoBert

Link to comment
Share on other sites

Here is a way to write individual items to Excel

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>
#include <String.au3>
#include <Array.au3>

Global $ActiveTab
Dim $row = 0
$oExcel = _ExcelBookNew()

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 444, 192, 124)
$Tab1 = GUICtrlCreateTab(32, 32, 545, 337)
$TabSheet1 = GUICtrlCreateTabItem("tab1")
$ListView1 = GUICtrlCreateListView("ID1|NAME1|OTHER1", 40, 64, 530, 294)
GUICtrlCreateListViewItem('1|a|65786315', $ListView1)
GUICtrlCreateListViewItem('2|b|56454688', $ListView1)
GUICtrlCreateListViewItem('3|c|86575765', $ListView1)
GUICtrlCreateListViewItem('4|d|87654832', $ListView1)
GUICtrlCreateListViewItem('5|e|96325478', $ListView1)
GUICtrlCreateListViewItem('6|f|64651873', $ListView1)
GUICtrlCreateListViewItem('7|g|96437251', $ListView1)
GUICtrlCreateListViewItem('8|h|64976835', $ListView1)
$TabSheet2 = GUICtrlCreateTabItem("tab2")
$ListView2 = GUICtrlCreateListView("ID2|NAME2|OTHER2", 40, 64, 529, 297)
GUICtrlCreateListViewItem('1|aa|6aasdx123', $ListView2)
GUICtrlCreateListViewItem('2|bb|5bbsdx123', $ListView2)
GUICtrlCreateListViewItem('3|cc|8ccsdx123', $ListView2)
GUICtrlCreateListViewItem('4|dd|8ddsdx123', $ListView2)
GUICtrlCreateListViewItem('5|ee|9eesdx123', $ListView2)
GUICtrlCreateListViewItem('6|ff|6ffsdx123', $ListView2)
GUICtrlCreateListViewItem('7|gg|9ggsdx123', $ListView2)
GUICtrlCreateListViewItem('8|hh|6hhsdx123', $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
        Case $Tab1
            $ActiveTab = GUICtrlRead($Tab1)
        Case $Button1
            WriteExcel($ActiveTab)
    EndSwitch
WEnd

Func WriteExcel($ActiveTab)
    $row = $row + 1
    $dick = GUICtrlRead(GUICtrlRead($ListView1))
    If $ActiveTab = 1 Then $dick = GUICtrlRead(GUICtrlRead($ListView2))
    $array1 = _StringExplode($dick, "|", 0)
    For $i = 0 To 3
        _ExcelWriteCell($oExcel, $array1[$i], $row, 1 + $i)
    Next
EndFunc   ;==>WriteExcel

REB (Edited Code)

Edited by reb

MEASURE TWICE - CUT ONCE

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...