danrim

grab info from IE/ fill excell / save as pdf

Sep 16th, 2020
1,288
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance, Force
  2.  
  3.  
  4. ^o::
  5. pwb := WBGet()
  6.  
  7. ;~ var := pwb.LocationURL ; -------------------------------------------------------------------------------- Grab URL
  8. ;~ MsgBox, %var%
  9.  
  10. Sleep, 100
  11. If !WinExist("DELFI Žinios - Pagrindinis naujienų portalas Lietuvoje - Internet Explorer") ; ------------ Check If SN Window Exist
  12.     {
  13.         MsgBox, SN window does not exist
  14.         return
  15.     }
  16. else
  17.     {
  18.         WinMaximize, DELFI Žinios - Pagrindinis naujienų portalas Lietuvoje - Internet Explorer
  19.         WinWait, DELFI Žinios - Pagrindinis naujienų portalas Lietuvoje - Internet Explorer  
  20.     }
  21.  
  22. ;*******************************************************************
  23. while pwb.busy or pwb.ReadyState !=4 ;wait for page to load
  24.     Sleep, 50
  25. ;*******************************************************************
  26.  
  27. sleep 3000
  28. abcTest := pwb.document.getElementsByTagName("a")[107].innerHTML ; ar innerText Reikia?
  29. ;~ MsgBox %abcTest%
  30. ;~ sleep 3000
  31. ;~ pwb.document.getElementsByTagName("a")[106].focus()
  32. ;~ sleep 3000
  33. ;~ pwb.document.getElementsByTagName("a")[106].click()
  34. ;~ Sleep 3000
  35. WinMinimize, DELFI Žinios - Pagrindinis naujienų portalas Lietuvoje - Internet Explorer
  36. ;~ MsgBox %abcTest%
  37. sleep 100
  38.  
  39.  
  40.  
  41. ; ---------------------------- Insert data from SN (browser) to Excel and create pdf --------------------------------------
  42.  
  43. FormatTime, MyTime,,dd/MM/yyyy
  44.  
  45. todayDateVar := MyTime
  46. referanseAvtaleSNvar := 1111111
  47. tilbudsNrVar := 222222
  48. beløp := 200
  49. kundesNavnSNvar := "bob"
  50. kundensEtterNavnVar := "Andresen"
  51. kundensAdressenVar := "Veien 23"
  52. kundensPostVar := "Norge 2200"
  53. kidNrSnVar := "1111112222222223333333333"
  54.  
  55.  
  56. ; CRTL+SHIFT+g Object COM Tester
  57. ;~ ^+g::
  58. ;~ KeyWait, g
  59. WorkbookPath := "C:\Users\abc\Desktop\ahk_stuff\kontantklausul_brev\test.xlsx" ;"C:\Users\abc\Desktop\test.xlsx" ;A_ScriptDir "\!!VIEWER work order (Template).xlsx"
  60. objWorkBook := objExcel.Workbooks.Add
  61.  
  62. xlApp := ComObjCreate("Excel.Application") ; Create an instance of Excel
  63. xlApp.Visible := true ; Make Excel visible
  64. brevContent := xlApp.Workbooks.Open(WorkbookPath) ; Open a workbook and store a reference to it in VideoViewerWorkOrder var
  65. brevContent.Sheets("Sheet1").Range("A1").Value := todayDateVar
  66. Sleep, 20
  67. brevContent.Sheets("Sheet1").Range("C4").Value := kundensEtterNavnVar
  68. Sleep, 20
  69. brevContent.Sheets("Sheet1").Range("I4").Value := kundesNavnSNvar
  70. Sleep, 20
  71. brevContent.Sheets("Sheet1").Range("C5").Value :=  kundensAdressenVar
  72. Sleep, 20
  73. brevContent.Sheets("Sheet1").Range("C6").Value :=  kundensPostVar
  74. Sleep, 20
  75. brevContent.Sheets("Sheet1").Range("C10").Value :=  kidNrSnVar
  76. Sleep, 20
  77. brevContent.Sheets("Sheet1").Range("C11").Value :=  beløp
  78. Sleep, 20
  79. brevContent.Sheets("Sheet1").Range("C12").Value :=  referanseAvtaleSNvar
  80. Sleep, 20
  81.  
  82. ;---------------- Testas ar paima browserio value ----------------------
  83. brevContent.Sheets("Sheet1").Range("A16").Value :=  abcTest
  84.  
  85. WorkbookPathSave := "C:\Users\abc\Desktop\ahk_stuff\kontantklausul_brev\Tilbudsnr_" tilbudsNrVar ".pdf" ;A_ScriptDir "\" _DLinkJobNumber " Video Viewer.xlsx"
  86. ;~ MsgBox % WorkbookPathSave
  87.  
  88. xlapp.ActiveSheet.ExportAsFixedFormat(0,WorkbookPathSave,0,True,False,1,1,False)  
  89. ;~ xlApp.ActiveWorkbook.SaveAs(WorkbookPathSave)                                    ; creates pdf file but during opening get fail message 
  90. Sleep, 100
  91. brevContent.Close(0) ; Close the document without saving
  92. Sleep, 100
  93. xlApp.Quit()
  94. Sleep, 100
  95. Run,Tilbudsnr_%tilbudsNrVar%.pdf, C:\Users\abc\Desktop\ahk_stuff\kontantklausul_brev
  96. Return
  97.  
  98.  
  99.  
  100.  
  101.  
  102. ; ---------------------------- IE WEB SCRAPPING CONNETION SCRIPT ------------------------------------
  103.  
  104. WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
  105.    static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
  106.         , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
  107. ;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
  108.    SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
  109.    if (ErrorLevel != "FAIL") {
  110.       lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
  111.       if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
  112.          DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
  113.          return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
  114.       }
  115.    }
  116. }
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. ^+x::ExitApp
RAW Paste Data