Page 1 of 1

[functions] RotateTable

Posted: 26 Dec 2015, 14:44
by Learning one
Continued from old [functions] RotateTable thread.

Re: [functions] RotateTable

Posted: 18 Jun 2021, 10:46
by emmanuel d
hmm, i was not getting the result i wanted.
So i made my own version
Now i can go in excel copy a range, run script, dismiss msgbox, and paste back in excel

Code: Select all

#SingleInstance force   
oOldTable := StrToArray(clipboard)                ; Create a array
oNewTable := ArrayRotateLeft(oOldTable)           ; rotate it
MsgBox,262144,%A_ThisFunc%,% clipboard:=StrFromArray(oNewTable),3 ; make it text and put it on the clipboard
return
ArrayRotateLeft(L_oArray) {                       ; Rotate Array Left By EMDK
	L_Ret       := []
	, L_TotRows := L_oArray.1.MaxIndex()
	, L_TotCol  := L_oArray.MaxIndex()
	Loop, % L_TotRows                               ; Loop all future rows
		L_Ret.Insert([])                              ; Create a aray to contain the row data
	For L_Dummy,L_oRow in L_oArray {                ; loop rows
		L_Col := A_Index + L_TotCol - 1               ; First item in the row becomes the last column
		For L_Dummy,L_Value in L_oRow {               ; loop columns
			L_Row:= L_TotRows - A_Index + 1             ; Last item in the columns becomes the first row
			L_Ret[L_Row][L_Col] := L_Value              ; Add the Item to the new array
			}
		}
	return L_Ret
	}
StrFromArray(oTable,L_DelRow:="`n",L_DelCol:="`t") {
	L_Row :="" , L_Ret := ""                        ; initialize variables before using .=
	For k,v in oTable{                              ; loop the rows
		For k2,v2 in v                                ; loop the columns
			L_Row .= L_DelCol v2                        ; Add the column data to the row
		L_Row   := SubStr(L_Row, 1+StrLen(L_DelCol))  ; remove the first delimiter
		L_Ret   .= L_DelRow L_Row                     ; Add the row to the Return variable
		L_Row   := ""                                 ; Reset the variable for the next row
		}
	return SubStr(L_Ret, 1+StrLen(L_DelRow))        ; Return the var, but remove the delimiter from the start
	}
StrToArray(L_Str,L_DelCol:="	",L_DelRow:="`n",L_OmitChars:="`r"){
	L_Array := []
	Loop,Parse,L_Str,%L_DelRow%,%L_OmitChars%
		L_Array[A_Index] := StrSplit(A_LoopField,L_DelCol,L_OmitChars) 
	Return,L_Array
	}