Netol Posted July 21 Share Posted July 21 (edited) 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 July 21 by Netol Link to comment Share on other sites More sharing options...
Andreik Posted July 21 Share Posted July 21 What exactly do you mean by list? Link to comment Share on other sites More sharing options...
Netol Posted July 21 Author Share Posted July 21 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 More sharing options...
Andreik Posted July 21 Share Posted July 21 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) Netol 1 Link to comment Share on other sites More sharing options...
Netol Posted July 21 Author Share Posted July 21 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 More sharing options...
Andreik Posted July 21 Share Posted July 21 Post the excel file or a sample. Link to comment Share on other sites More sharing options...
Netol Posted July 21 Author Share Posted July 21 38 minutes ago, Andreik said: Post the excel file or a sample. This is the excel file. test.xlsx Link to comment Share on other sites More sharing options...
Solution Andreik Posted July 21 Solution Share Posted July 21 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 Netol 1 Link to comment Share on other sites More sharing options...
Netol Posted July 21 Author Share Posted July 21 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 Link to comment Share on other sites More sharing options...
Andreik Posted July 21 Share Posted July 21 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. Link to comment Share on other sites More sharing options...
Netol Posted July 22 Author Share Posted July 22 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now