Advertisement
KRG-23

grid

Feb 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;==================================================
  2. ;FILE MUST BE OPENED BEFORE RUNNING SCRIPT
  3. ;==================================================
  4. GLOBAL      xlup                = -4162
  5. GLOBAL      xldown              = -4121
  6. GLOBAL      xlLeft              = -4159
  7. GLOBAL      xlRight             = -4161
  8.  
  9. ;This is the function i use for grabbing open/active excel workbooks - you dont need to use this, but its what i prefer :)
  10. xl := XL_Check()
  11.  
  12. ;Get the length of headers to loop through - im assuming headers start at A1 - and are always in Row 1
  13. HeaderColumns := xl.sheets("sheet1").range("A1").end(xlright)["column"]
  14. Loop % HeaderColumns
  15. {
  16.     ;Convert Index number to letter so we can loop easily through the columns(1=A, 2=B, 3=C, etc....)
  17.     Col := ConverttoLetter(A_Index) ;Helper Function Below
  18.     Header := xl.sheets("sheet1").range(Col "1").value
  19.    
  20.     ;Get the length of data within that column - we can now loop through it and create our Gui
  21.     Rows := xl.sheets("sheet1").range(col "2").end(xldown)["row"]
  22.     Gui, Add, text, w100 x+10 ym, % Header
  23.     Loop % Rows - 1
  24.     {
  25.         RowContent := xl.sheets("sheet1").range(Col A_Index + 1).value
  26.         Gui, add, edit,,% RowContent
  27.     }
  28.  
  29. }
  30.  
  31. gui,show,autosize
  32. return
  33.  
  34.  
  35. ESC::
  36. guiclose:
  37. exitapp
  38.  
  39. ConvertToLetter(n)
  40. {
  41.     while (n != 0) {
  42.         t := Mod((n - 1), 26)
  43.         n := (n - t) // 26
  44.         l := chr(65 + t) l
  45.     }
  46.     return l
  47. }
  48.  
  49. ConvertToNumbers(l)
  50. {
  51.     colnum:=0
  52.     Loop % strlen(l)
  53.         colnum := (colnum*26) + (asc(SubStr(l,A_Index,1))-64)
  54.     return colnum+0
  55. }
  56.  
  57. XL_Check(WinTitle:="ahk_class XLMAIN", Excel7#:=1) {
  58.     static h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
  59.     WinGetClass, WinClass, %WinTitle%
  60.     if !(WinClass == "XLMAIN")
  61.         return "Window class mismatch."
  62.     ControlGet, hwnd, hwnd,, Excel7%Excel7#%, %WinTitle%
  63.     if (ErrorLevel)
  64.         return "Error accessing the control hWnd."
  65.     VarSetCapacity(IID_IDispatch, 16)
  66.     NumPut(0x46000000000000C0, NumPut(0x0000000000020400, IID_IDispatch, "Int64"), "Int64")
  67.     if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", -16, "Ptr", &IID_IDispatch, "Ptr*", pacc) != 0
  68.         return "Error calling AccessibleObjectFromWindow."
  69.     window := ComObject(9, pacc, 1)
  70.     if ComObjType(window) != 9
  71.         return "Error wrapping the window object."
  72.     Loop
  73.         try return window.application
  74.     catch e
  75.         if SubStr(e.message, 1, 10) = "0x80010001"
  76.             ControlSend, Excel7%Excel7#%, {Esc}, %WinTitle%
  77.     else
  78.         return "Error accessing the application object."
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement