Advertisement
KRG-23

test_XLSMNGMT

Feb 20th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. OnExit, CleanUp ; Runs the specified subroutine when the script closes
  2. SetWorkingDir %A_ScriptDir%
  3. ; ==================================================
  4. ; GLOBAL VARIABLES
  5. ; ==================================================
  6.  
  7. xlApp := ComObjCreate("Excel.Application") ; Create an instance of Excel
  8. Margin := 10, 10 ; Margin of the UI
  9. ; WorkDir := "D:\Perso\Taff\Scania\Scripts\CMC\test.xlsx" ; Where is the script located
  10. WorkDir := A_ScriptDir "\test.xlsx" ; Where is the script located
  11. Clients_List := "ALL||Client1|Cllient2|Client3" ; Will fill the DropDownList with clients IDs
  12. Header_Range := "A1;B1;D1;F1;G1;H1;L1" ; Header's range in Excel file
  13. Cell_Range := "A2;B2;D2;F2;G2;H2;L2" ; First row of value (temporary test)
  14. Sheet_Name := "Sheet1" ; Sheet name, may change in the future, depends on the extracted Excel file
  15.  
  16. ; Excel is invisible by default. Once you have tested the script this line can be removed.
  17. xlApp.Visible := true
  18. ; xlApp.Visible := false
  19.  
  20.  
  21. ; ==================================================
  22. ; Gui
  23. ; ==================================================
  24. ; Create the GUI. Add text, edit boxes, and buttons, then show the GUI.
  25.     Gui, Color, FFFFFF
  26.     Gui, Font, s12 Bold c000000, Century Gothic
  27.     Gui, Add, Button, Section xm w100 gLoad, Load
  28.     ; Headers content
  29.     Gui, Add, Button, Section xm y+10 w140, Keep it? ; Hidden to keep UI elements aligned
  30.     Gui, Add, Button, ys wp vHeader_1, ; Header Title in cell A1
  31.     Gui, Add, Button, ys wp vHeader_2, ; Header Change Number in cell B1
  32.     Gui, Add, Button, ys wp vHeader_3, ; Header Change Type in cell D1
  33.     Gui, Add, Button, ys wp vHeader_4, ; Header Planned Start in cell F1
  34.     Gui, Add, Button, ys wp vHeader_5, ; Header Planned End in cell G1
  35.     Gui, Add, Button, ys wp vHeader_6, ; Header Change open in cell H1
  36.     Gui, Add, Button, ys wp vHeader_7 ; Header Main Altered CI list in cell L1
  37.     Gui, Add, Button, ys wp, Clients ; Header Clients list in cell R1
  38.     ; Rows content
  39.     Gui, Add, Checkbox, Section xm y+10 w140 vKeep, ; Check box to remove line
  40.     Gui, Font,
  41.     Gui, Font, s8 c000000, Verdana
  42.     Gui, Add, Edit, Hidden wp ys r3 vE1,
  43.     Gui, Add, Edit, Hidden wp ys vE2,
  44.     Gui, Add, Edit, Hidden wp ys vE3,
  45.     Gui, Add, Edit, Hidden wp ys vE4,
  46.     Gui, Add, Edit, Hidden wp ys vE5,
  47.     Gui, Add, Edit, Hidden wp ys vE6,
  48.     Gui, Add, Edit, Hidden wp ys vE7,
  49.     Gui, Add, DDL, wp ys vE8, %Clients_List%
  50.     Gui, Font, s12 Bold c000000, Century Gothic
  51.     Gui, Add, Button, Section xm y+50 w80 h25 gGuiClose, Quit
  52.     Gui, Show, ,CMC - Changes of the day
  53. return ; End of auto-execute section
  54.  
  55. ; ==================================================
  56. ; LABELS
  57. ; ==================================================
  58. GuiEscape:
  59. GuiClose:
  60.     ; Gosub, CleanUp
  61.     ExitApp
  62. return
  63.  
  64.  
  65. Load:
  66. if (MyWorkbook) ; for simplicity, we don't want to be able to open multiple workbooks.
  67.     return
  68.  
  69. ; FileSelectFile, MyFile, 3,, Select an Excel workbook file., Excel (*.xls; *.xlsx)
  70. ; if (ErrorLevel) ; The user dismissed the file dialog without selecting anything.
  71.     ; return
  72.    
  73. MyFile := WorkDir
  74. MyWorkbook := xlApp.Workbooks.Open(MyFile) ; Open the file in Excel
  75.  
  76. ; Counts total of not empty rows in column B (change number)
  77. xlApp := ComObjActive("Excel.Application")
  78. Row_Number := % xlApp.Worksheets("Sheet1").Range("B:M").Cells.SpecialCells(2).Count ; xlCellTypeConstants = 2
  79.  
  80.  
  81. ; Read headers in the range A1:B1;D1;F1:G1;L1. Update the GUI.
  82. for MyRange, in MyWorkbook.Sheets(Sheet_Name).Range(Header_Range)
  83. {
  84.     GuiControl,, Header_%A_Index%, % MyRange.Text
  85. }
  86.  
  87. for MyRange, in MyWorkbook.Sheets(Sheet_Name).Range(Cell_Range)
  88.     {
  89.     GuiControl, Show, E%A_Index%,
  90.     GuiControl,, E%A_Index%, % MyRange.Text
  91.     ; Gui, Add, Edit, wp ys vE%A_Index%, % MyRange.Text
  92.     }
  93.     ; Else
  94.         ; Break
  95.     ; }
  96. Return
  97.  
  98.  
  99.  
  100. CleanUp: ; This will cleanup before the script exits
  101. MyWorkbook.Close(0) ; 0 = don't save changes. Changes should have already been saved.
  102. xlApp.Quit()
  103. ExitApp
  104.  
  105.  
  106.  
  107.  
  108. ; ==================================================
  109. ; FUNCTIONS
  110. ; ==================================================
  111.  
  112.  
  113.  
  114. ; ==================================================
  115. ; HOTKEYS
  116. ; ==================================================
  117. F11::ListVars
  118. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement