ahmeddzcom Posted January 13, 2023 Share Posted January 13, 2023 (edited) Hello I need Get Array From Array _ArrayDelete working fine on this code #include <array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen(_Excel_Open(), @ScriptDir&"\E.xlsx") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error opening E.xlsx") Local $aExcel = _Excel_RangeRead($oWorkbook, 1) $1 = $aExcel $Find = _ArrayFindAll($aExcel, "2", Default, Default, Default, Default,5) _ArrayInsert($Find, 0, UBound($Find)) _ArrayDelete($aExcel, $Find) $2 = $aExcel _ArrayDisplay($1) _ArrayDisplay($2) But i need get All Rows containing the value 2 on Column 5 difference between two arrays Tnx. E.xlsx Edited January 13, 2023 by ahmeddzcom Link to comment Share on other sites More sharing options...
ioa747 Posted January 13, 2023 Share Posted January 13, 2023 Try this if ok #include <array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen(_Excel_Open(), @ScriptDir&"\E.xlsx") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error opening E.xlsx") Local $aExcel = _Excel_RangeRead($oWorkbook, 1) _ArrayDisplay($aExcel) Local $aResult = _ArrayFindAll($aExcel, 2, Default, Default, Default, Default, 5) _ArrayDisplay($aResult, "Found in Column 5") I know that I know nothing Link to comment Share on other sites More sharing options...
ahmeddzcom Posted January 13, 2023 Author Share Posted January 13, 2023 12 minutes ago, ioa747 said: Try this if ok i need difference between two arrays 😄 Link to comment Share on other sites More sharing options...
ioa747 Posted January 13, 2023 Share Posted January 13, 2023 I don't understand, the difference is that you deleted it or you're just looking for a way to confirm it? I know that I know nothing Link to comment Share on other sites More sharing options...
ahmeddzcom Posted January 13, 2023 Author Share Posted January 13, 2023 (edited) 22 minutes ago, ioa747 said: I don't understand, the difference is that you deleted it or you're just looking for a way to confirm it? i need get All Rows containing the value 2 on Column 5 Edited January 13, 2023 by ahmeddzcom Link to comment Share on other sites More sharing options...
ioa747 Posted January 13, 2023 Share Posted January 13, 2023 and what it gives you this? #include <array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen(_Excel_Open(), @ScriptDir&"\E.xlsx") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error opening E.xlsx") Local $aExcel = _Excel_RangeRead($oWorkbook, 1) ;~ _ArrayDisplay($aExcel) Local $aResult = _ArrayFindAll($aExcel, 2, Default, Default, Default, Default, 5) _ArrayDisplay($aResult, "Found in Column 5") I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted January 13, 2023 Share Posted January 13, 2023 (edited) or in comparison #include <array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen(_Excel_Open(), @ScriptDir & "\E.xlsx") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error opening E.xlsx") Local $aExcel = _Excel_RangeRead($oWorkbook, 1) $1 = $aExcel $Find = _ArrayFindAll($aExcel, "2", Default, Default, Default, Default, 5) _ArrayInsert($Find, 0, UBound($Find)) _ArrayDelete($aExcel, $Find) $2 = $aExcel ;~ _ArrayDisplay($1, "$1") ;~ _ArrayDisplay($2, "$2") For $x = 0 To $1[UBound($1) - 1][0] ConsoleWrite($1[$x][0] & "=" & _GetID($1[$x][0]) & @CRLF) Next Func _GetID($RowID) Local $ID For $i = 0 To $1[UBound($2) - 1][0] $ID = 0 If $RowID = $2[$i][0] Then $ID = $2[$i][0] ExitLoop EndIf Next Return $ID EndFunc ;==>_GetID Edited January 13, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted January 14, 2023 Share Posted January 14, 2023 I just noticed that $i = 0 is wrong because $RowID starts with 0. So it's better this way #include <array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen(_Excel_Open(), @ScriptDir & "\E.xlsx") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error opening E.xlsx") Local $aExcel = _Excel_RangeRead($oWorkbook, 1) $1 = $aExcel $Find = _ArrayFindAll($aExcel, "2", Default, Default, Default, Default, 5) _ArrayInsert($Find, 0, UBound($Find)) _ArrayDelete($aExcel, $Find) $2 = $aExcel ;~ _ArrayDisplay($1, "$1") ;~ _ArrayDisplay($2, "$2") For $x = 0 To $1[UBound($1) - 1][0] ConsoleWrite($1[$x][0] & "=" & _GetID($1[$x][0]) & @CRLF) Next Func _GetID($RowID) Local $ID For $i = 0 To $1[UBound($2) - 1][0] $ID = "REMOVED" If $RowID = $2[$i][0] Then $ID = $2[$i][0] ExitLoop EndIf Next Return $ID EndFunc ;==>_GetID I know that I know nothing Link to comment Share on other sites More sharing options...
pixelsearch Posted January 14, 2023 Share Posted January 14, 2023 I think OP would like to easily extract some non-contiguous full rows from an array, when the row indices are indicated in an external 1D array. For example something like this, using... a non-existant function : Local $aExtract = _ArrayExtractEx($aExcel, $aIndices) IIRC Melba23 added this functionality to _ArrayDelete (and _ArrayInsert too ?), I mean the possibility of using a range of indices in a 1D array. By the way, OP used this functionality when he scripted : _ArrayDelete($aExcel, $Find) $Find being a 1D array of indices, returned by _ArrayFindAll Of course it should be easy for OP to extract these full rows in a loop, based on the $Find array, but it would be easier with a one liner. But wait... maybe it's already possible and I missed it, everything is possible ahmeddzcom 1 Link to comment Share on other sites More sharing options...
mikell Posted January 14, 2023 Share Posted January 14, 2023 ? #include <array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open(False) Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir&"\E.xlsx", False, False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error opening E.xlsx") $value = "2" $a = StringRegExp(_ArrayToString(_Excel_RangeRead($oWorkbook)), '(?m)^(?:[^\|]*\|){5}' & $value & '\|.*$', 3) Local $res[0][12] For $i = 0 to UBound($a)-1 _ArrayAdd($res, $a[$i]) Next _ArrayDisplay($res) pixelsearch, ioa747 and ahmeddzcom 3 Link to comment Share on other sites More sharing options...
ahmeddzcom Posted January 14, 2023 Author Share Posted January 14, 2023 40 minutes ago, mikell said: ? #include <array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open(False) Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir&"\E.xlsx", False, False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error opening E.xlsx") $value = "2" $a = StringRegExp(_ArrayToString(_Excel_RangeRead($oWorkbook)), '(?m)^(?:[^\|]*\|){5}' & $value & '\|.*$', 3) Local $res[0][12] For $i = 0 to UBound($a)-1 _ArrayAdd($res, $a[$i]) Next _ArrayDisplay($res) Nice Work Mr.@mikell Can do this without StringRegExp ? Link to comment Share on other sites More sharing options...
ahmeddzcom Posted January 14, 2023 Author Share Posted January 14, 2023 7 hours ago, pixelsearch said: But wait... maybe it's already possible and I missed it, everything is possible Exact . But i can't do this. 😔 Link to comment Share on other sites More sharing options...
Solution mikell Posted January 14, 2023 Solution Share Posted January 14, 2023 (edited) 4 hours ago, ahmeddzcom said: Can do this without StringRegExp ? Of course you can Once the $aExcel array is converted to a string then you can use StringSplit, details below #include <array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open(False) Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir&"\E.xlsx", False, False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error opening E.xlsx") Local $value = "2", $col = 5 $aExcel = _Excel_RangeRead($oWorkbook) Local $res[0][UBound($aExcel, 2)] $txt = _ArrayToString($aExcel) #cs $a = StringRegExp($txt, '(?m)^(?:[^\|]*\|){' & $col & '}' & $value & '\|.*$', 3) For $i = 0 to UBound($a)-1 _ArrayAdd($res, $a[$i]) Next #ce $rows = StringSplit($txt, @crlf, 1) For $i = 1 to $rows[0] $cells = StringSplit($rows[$i], "|", 2) If $cells[$col] = $value Then _ArrayAdd($res, $rows[$i]) Next _ArrayDisplay($res) Edited January 14, 2023 by mikell ahmeddzcom 1 Link to comment Share on other sites More sharing options...
ahmeddzcom Posted January 14, 2023 Author Share Posted January 14, 2023 Tnx @mikell 😃 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