[functions] RotateTable
- Learning one
- Posts: 173
- Joined: 04 Oct 2013, 13:59
- Location: Croatia
- Contact:
[functions] RotateTable
Continued from old [functions] RotateTable thread.
My Website • Join DropBox
- emmanuel d
- Posts: 90
- Joined: 17 Nov 2013, 04:45
Re: [functions] RotateTable
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
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
}
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: Kobaltauge, laoyugong and 140 guests