Jump to content

convert array to list


Go to solution Solved by Andreik,

Recommended Posts

hello my friend,

just to ask about a code that conver array to list

i have the next code and i need to put the array result to an list

 

        Local $oExcel =_Excel_Open()

        $datawb = _Excel_BookOpen($oExcel,@ScriptDir & "\test.xlsx")
        ; $datawb.worksheets("info").select
        $LastRow = $datawb.ActiveSheet.UsedRange.Rows.Count
        $mydata = _Excel_RangeRead($datawb, Default,Default )
        If IsArray($mydata) Then _ArrayDisplay($mydata)

        _Excel_BookClose($datawb)
 

 

Best regards

Edited by Netol
Link to comment
Share on other sites

39 minutes ago, Andreik said:

What exactly do you mean by list?

Thanks for your responce

i need to convert the array to listview

GUICtrlCreateListView

Link to comment
Share on other sites

If you want to create a list view item for each index from array then you can do it like this:

; Create a GUI here

;~ $cList = GUICtrlCreateList()

Local $oExcel =_Excel_Open()

$datawb = _Excel_BookOpen($oExcel,@ScriptDir & "\test.xlsx")
; $datawb.worksheets("info").select
$LastRow = $datawb.ActiveSheet.UsedRange.Rows.Count
$mydata = _Excel_RangeRead($datawb, Default,Default )
If IsArray($mydata) Then _ArrayDisplay($mydata)
For $Index = 0 To UBound($mydata) - 1
    GUICtrlCreateListViewItem($mydata[$Index], $cList)
Next

_Excel_BookClose($datawb)

 

When the words fail... music speaks.

Link to comment
Share on other sites

36 minutes ago, Andreik said:

If you want to create a list view item for each index from array then you can do it like this:

; Create a GUI here

;~ $cList = GUICtrlCreateList()

Local $oExcel =_Excel_Open()

$datawb = _Excel_BookOpen($oExcel,@ScriptDir & "\test.xlsx")
; $datawb.worksheets("info").select
$LastRow = $datawb.ActiveSheet.UsedRange.Rows.Count
$mydata = _Excel_RangeRead($datawb, Default,Default )
If IsArray($mydata) Then _ArrayDisplay($mydata)
For $Index = 0 To UBound($mydata) - 1
    GUICtrlCreateListViewItem($mydata[$Index], $cList)
Next

_Excel_BookClose($datawb)

 

thanks a lot,

In my code autoit dont open in a excel, just put excel to a array data.

and the autoit display an error
Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

the range of excel is variable, but in this case is "A1:A48" cells

 

i changed only one line

 

        Local $oExcel =_Excel_Open()

        $datawb = _Excel_BookOpen($oExcel,@ScriptDir & "\test.xlsx")
        ; $datawb.worksheets("info").select
        $LastRow = $datawb.ActiveSheet.UsedRange.Rows.Count
        $mydata = _Excel_RangeRead($datawb, Default,Default )
        If IsArray($mydata) Then _ArrayDisplay($mydata)
        For $Index = 0 To UBound($mydata) - 1
             GUICtrlCreateListViewItem($mydata[$Index], $List1)
        Next
        _Excel_BookClose($datawb)

Link to comment
Share on other sites

  • Solution

Example for first two columns, you can do it for all columns:

#include <Excel.au3>

$hGUI = GUICreate('Test', 600, 400)
$cList = GUICtrlCreateListView('Cámara|7/12/2024', 10, 10, 580, 380)
GUISetState(@SW_SHOW, $hGUI)

LoadExcel($cList, @ScriptDir & '\test.xlsx')

Do
Until GUIGetMsg() = -3

Func LoadExcel($cList, $sPath)
    Local $oExcel =_Excel_Open(False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $sPath)
    Local $vData = _Excel_RangeRead($oWorkbook)
    If Not IsArray($vData) Then Return SetError(1, 0, 0)
    For $Index = 1 To UBound($vData) - 1
        GUICtrlCreateListViewItem($vData[$Index][0] & '|' & $vData[$Index][1], $cList)
    Next
    _Excel_BookClose($oWorkbook)
    _Excel_Close($oExcel)
EndFunc

 

When the words fail... music speaks.

Link to comment
Share on other sites

41 minutes ago, Andreik said:

Example for first two columns, you can do it for all columns:

#include <Excel.au3>

$hGUI = GUICreate('Test', 600, 400)
$cList = GUICtrlCreateListView('Cámara|7/12/2024', 10, 10, 580, 380)
GUISetState(@SW_SHOW, $hGUI)

LoadExcel($cList, @ScriptDir & '\test.xlsx')

Do
Until GUIGetMsg() = -3

Func LoadExcel($cList, $sPath)
    Local $oExcel =_Excel_Open(False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $sPath)
    Local $vData = _Excel_RangeRead($oWorkbook)
    If Not IsArray($vData) Then Return SetError(1, 0, 0)
    For $Index = 1 To UBound($vData) - 1
        GUICtrlCreateListViewItem($vData[$Index][0] & '|' & $vData[$Index][1], $cList)
    Next
    _Excel_BookClose($oWorkbook)
    _Excel_Close($oExcel)
EndFunc

 

I copy your code and this is the resut.

Dont copy the data

2024-07-21_17-38-57.jpg

Link to comment
Share on other sites

You should really start to learn basics of AutoIt. Literally there is only one place in the code where the function might end before loading the list view with items and this place is where the result of _Excel_RangeRead() is verified to be an array. It might also be possible to exist a small delay if you have a potato PC and a large set of data. Anyway, if I were you I would take a break and get a basic understanding of the language.

When the words fail... music speaks.

Link to comment
Share on other sites

2 hours ago, Andreik said:

You should really start to learn basics of AutoIt. Literally there is only one place in the code where the function might end before loading the list view with items and this place is where the result of _Excel_RangeRead() is verified to be an array. It might also be possible to exist a small delay if you have a potato PC and a large set of data. Anyway, if I were you I would take a break and get a basic understanding of the language.

Hello, I am learning and I am not an expert, that is why I consult in this group that is created to help those who have questions.

I managed to modify the code and solved the problem.
Here is my code:

 

#include <Excel.au3>

$hGUI = GUICreate('Test', 600, 400)
$List1 = GUICtrlCreateListView('Cámara|12-07-2024|28-06-2024|17-06-2024|31-05-2024|17-05-2024|03-05-2024|19-04-2024|05-04-2024|22-03-2024|08-03-2024|23-02-2024|09-02-2024|02-02-2024|26-01-2024|19-01-2024|12-01-2024', 10, 10, 580, 380)
GUISetState(@SW_SHOW, $hGUI)

LoadExcel($List1, "C:\Mis Documentos\_clientes\EBCO\Centro comercial Chicureo\Aplicación Navegación" & '\test.xlsx')

Do
Until GUIGetMsg() = -3

Func LoadExcel($cList, $sPath)
    Local $oExcel =_Excel_Open(False)
    Local $oWorkbook = _Excel_BookOpen($oExcel, $sPath)
    Local $vData = _Excel_RangeRead($oWorkbook)
    sleep(200)
    ; MsgBox($MB_SYSTEMMODAL, "$vData", $vData)

    If Not IsArray($vData) Then Return SetError(1, 0, 0)
    For $Index = 1 To UBound($vData) - 1
        GUICtrlCreateListViewItem($vData[$Index][0] & '|' & $vData[$Index][1] _
                                  & '|' & $vData[$Index][2] _
                                  & '|' & $vData[$Index][3] _
                                  & '|' & $vData[$Index][4] _
                                  & '|' & $vData[$Index][5] _
                                  & '|' & $vData[$Index][6] _
                                  & '|' & $vData[$Index][7] _
                                  & '|' & $vData[$Index][8] _
                                  & '|' & $vData[$Index][9] _
                                  & '|' & $vData[$Index][10] _
                                  & '|' & $vData[$Index][11] _
                                  & '|' & $vData[$Index][12] _
                                  & '|' & $vData[$Index][13] _
                                  & '|' & $vData[$Index][14] _
                                  & '|' & $vData[$Index][15] _
                                  & '|' & $vData[$Index][16] _
                                  , $List1)

        ; GUICtrlCreateListViewItem($vData[$Index][0] & '|' & $vData[$Index][2], $cList)
    Next
    _Excel_BookClose($oWorkbook)
    _Excel_Close($oExcel)
EndFunc

 

 

 

thank you

 

 

 

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...