Jump to content
Sign in to follow this  
Fenzik

Xdoc2txt, extracting text from advanced documment formats, using DLL

Recommended Posts

Hello!

i wrote this function as alternative to using the Com Object or Commandline version of this project, discussed also earlyer on this forum.

Project site - http://ebstudio.info/home/xdoc2txt.html

Advantage of this implementation is that you do not need to register Com dll, using regsvr32.

But you still need the project Dll (xd2txlib.dll).

Enjoy!

; #FUNCTION# ====================================================================================================================
; Name ..........: _ExtractText
; Description ...: Extracts text from advanced documment formats (Doc, Docx, ODT, XLS, ...)
; Syntax ........: _ExtractText($sFilename[, $bProperties = False[, $hDll = 0]])
; Parameters ....: $sFilename           - a string value.
;                  $bProperties         - [optional] a boolean value. Default is False. If True, documment properties will be returned instead of the text.
;                  $hDll                - [optional] a handle value. Default is 0. Optional handle to previously opened xd2txlib.dll. By default the xd2txlib.dll (Expected in @scriptdir) will be opened and closed during the function call.
; Return value .: String, containing the text or documment properties or empty string and Error as follows:
;1 - The file does not exists.
;2 - Error during opening xd2txlib.dll.
;3 - No text returned.
; Author ........: Fenzik
; Modified ......:
; Remarks .......: Project site - http://ebstudio.info/home/xdoc2txt.html
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _ExtractText($sFilename, $bProperties = False, $hDll = 0)
If Not FileExists($sFilename) Then Return SetError(1, "", "")
Local $bLoaded = False
If $hDll = 0 Then
  $hDll = DllOpen(@scriptdir&"\xd2txlib.dll")
  If $hDll = -1 Then Return SetError(2, "", "")
$bLoaded = True
Endif
$aResult = DllCall($hDll, "int:cdecl", "ExtractText", "WSTR", $sFilename, "BOOL", $bProperties, "WSTR*", "")
If $aResult[0] = 0 Then Return SetError(3, "", "")
If $bLoaded = True Then DllClose($hDll)
Return $aResult[3]
EndFunc

 

 

xd2txlib-example.zip

Edited by Fenzik
Attached the example instead of original project.

Share this post


Link to post
Share on other sites

Here is easy example, including sample documment.

 

Edited by Fenzik
Example moved to the first post.

Share this post


Link to post
Share on other sites

Hi Fensik,

I made this small piece of code for testing and I got the following error: !>10:25:20 AutoIt3.exe ended.rc:-1073740940.

Would you please point me out what I'm doing wrong. Thanks in advance.

 

Global $bProperties, $hDll
Global $sMessage = "Hold down Ctrl or Shift to choose multiple files."
Global $sFileOpenDialog = FileOpenDialog($sMessage, @ScriptDir & "\", "Text files (*.docx;*.doc;*.rtf;*.wri;*.txt)|Excel (*.xls;*.xlsx)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
If @error Then
    MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.")
    Exit
Else
    FileChangeDir(@ScriptDir)
    $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
    MsgBox($MB_SYSTEMMODAL, "", "You chose the following files:" & @CRLF & $sFileOpenDialog)
EndIf

Global $FoundText = _ExtractText($sFileOpenDialog, $bProperties, $hDll) ; $bProperties = False --------------------------------
If Not @error Then ConsoleWrite($FoundText)
Exit

; #FUNCTION# ====================================================================================================================
; Name ..........: _ExtractText
; Description ...: Extracts text from advanced documment formats (Doc, Docx, ODT, XLS, ...)
; Syntax ........: _ExtractText($sFilename[, $bProperties = False[, $hDll = 0]])
; Parameters ....: $sFilename           - a string value.
;                  $bProperties         - [optional] a boolean value. Default is False. If True, documment properties will be returned instead of the text.
;                  $hDll                - [optional] a handle value. Default is 0. Optional handle to previously opened xd2txlib.dll. By default the xd2txlib.dll (Expected in @scriptdir) will be opened and closed during the function call.
; Return value .: String, containing the text or documment properties or empty string and Error as follows:
;1 - The file does not exists.
;2 - Error during opening xd2txlib.dll.
;3 - No text returned.
; Author ........: Fenzik
; Modified ......:
; Remarks .......: Project site - http://ebstudio.info/home/xdoc2txt.html
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _ExtractText($sFilename, $bProperties = False, $hDll = 0)
    If Not FileExists($sFilename) Then Return SetError(1, "", "")
    Local $bLoaded = False
    If $hDll = 0 Then
        $hDll = DllOpen(@ScriptDir & "\xd2txlib.dll")
        If $hDll = -1 Then Return SetError(2, "", "")
        $bLoaded = True
    EndIf
    $aResult = DllCall($hDll, "int:cdecl", "ExtractText", "WSTR", $sFilename, "BOOL", $bProperties, "WSTR*", "")
    If $aResult[0] = 0 Then Return SetError(3, "", "")
    If $bLoaded = True Then DllClose($hDll)
    Return $aResult[3]
EndFunc   ;==>_ExtractText

 

Share this post


Link to post
Share on other sites

Ok, i made few corrections and comments to your example.

 

So here it is..

#include <FileConstants.au3>
#include <msgboxconstants.au3>

Global $properties = False
Global $foundtext = ""
Global $sMessage = "Hold down Ctrl or Shift to choose multiple files."
Global $sFileOpenDialog = FileOpenDialog($sMessage, @ScriptDir & "\", "Text files (*.docx;*.doc;*.rtf;*.wri;*.txt)|Excel (*.xls;*.xlsx)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
If @error Then
  MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.")
  Exit
EndIf
;FileChangeDir(@ScriptDir)
;It's not necessary to change working dir here.
;Here we must know if user selected one or more files
If Not StringInStr($sFileOpenDialog, "|") Then
  ;Only one selected file
  MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & @CRLF & $sFileOpenDialog) ;Only one selected file
  ;so lets convert it here
  $foundtext = _ExtractText($sFileOpenDialog)
  ;in this case the DLL is opened and closed during function call.
  ;Properties are False by default so it's not necessary to use it if you want to have it false.
  ;show the result
  If Not @error Then ConsoleWrite($foundtext)
Else
  $files = StringSplit($sFileOpenDialog, "|") ;Multiple files
  ;The path is in $files[1], so we have to put the path and filenames together
  $sFileOpenDialog = ""
  For $i = 1 To $files[0] - 1
    $sFileOpenDialog &= $files[1] & "\" & $files[$i + 1] & @CRLF
  Next
  ;so here you have full paths to selected files divided by @crlf and you can show them in msgbox
  MsgBox($MB_SYSTEMMODAL, "", "You chose the following files:" & @CRLF & $sFileOpenDialog)
  ;And here is the problem. You passed whole set of files, divided by @crlf, with path to the directory only at the first line..
  ;Solet them be converted And showed one by one And pass the handle of previously opened DLL.
  $hXd2tx = DllOpen(@ScriptDir & "\xd2txlib.dll")
  $files = StringSplit($sFileOpenDialog, @CRLF)
  For $i = 1 To UBound($files) - 1
    $foundtext = _ExtractText($files[$i], $properties, $hXd2tx) ; $bProperties = False --------------------------------
    If Not @error Then ConsoleWrite($foundtext)
  Next
;Close the DLL
DllClose($hxd2tx)
EndIf

; #FUNCTION# ====================================================================================================================
; Name ..........: _ExtractText
; Description ...: Extracts text from advanced documment formats (Doc, Docx, ODT, XLS, ...)
; Syntax ........: _ExtractText($sFilename[, $bProperties = False[, $hDll = 0]])
; Parameters ....: $sFilename           - a string value.
;                  $bProperties         - [optional] a boolean value. Default is False. If True, documment properties will be returned instead of the text.
;                  $hDll                - [optional] a handle value. Default is 0. Optional handle to previously opened xd2txlib.dll. By default the xd2txlib.dll (Expected in @scriptdir) will be opened and closed during the function call.
; Return value .: String, containing the text or documment properties or empty string and Error as follows:
;1 - The file does not exists.
;2 - Error during opening xd2txlib.dll.
;3 - No text returned.
; Author ........: Fenzik
; Modified ......:
; Remarks .......: Project site - http://ebstudio.info/home/xdoc2txt.html
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _ExtractText($sFilename, $bProperties = False, $hDll = 0)
  If Not FileExists($sFilename) Then Return SetError(1, "", "")
  Local $bLoaded = False
  If $hDll = 0 Then
    $hDll = DllOpen(@ScriptDir & "\xd2txlib.dll")
    If $hDll = -1 Then Return SetError(2, "", "")
    $bLoaded = True
  EndIf
  $aResult = DllCall($hDll, "int:cdecl", "ExtractText", "WSTR", $sFilename, "BOOL", $bProperties, "WSTR*", "")
  If $aResult[0] = 0 Then Return SetError(3, "", "")
  If $bLoaded = True Then DllClose($hDll)
  Return $aResult[3]
EndFunc   ;==>_ExtractText

 

Edited by Fenzik

Share this post


Link to post
Share on other sites

And close the DLL at the end of conversion multiple files.

I forgot it and have problem to edit previous post...

Share this post


Link to post
Share on other sites

Fensik,

Thanks a lot for your reply. I run the code as you sent me and I got the same error: !>14:44:16 AutoIt3.exe ended.rc:-1073740940 when selecting .docx, .xlsx and .pdf.

I got Win 8.11 in a 64bit PC.

 

Share this post


Link to post
Share on other sites

Strange!

are you using last version of Autoit and Scite?

I have both last versions and everithing runs OK.

So try to update to the last versions.

And do you have the file xd2txlib.dll in the @scriptdir?

Share this post


Link to post
Share on other sites

I've got last versions of:

-SciTE Version 3.6.0
-Autoit 3.3.14.5
-xdoc2txt 32bit (x86) version (Windows OS is 32bit / 64bit) in the scriptdir.

I also tested it with xdoc2txt 32bit (x86) and xdoc2txt 64bit (x64) version and  I also install  "Microsoft Visual C ++ 2010 Redistributable Package (x86)" and "Microsoft Visual C ++ 2010 Redistributable Package (x64)" to avoid any dependency issue.

But even though it keeps showing the same error: !>17:08:44 AutoIt3.exe ended.rc:-1073740940
+>17:08:44 AutoIt3Wrapper Finished.

 

Share this post


Link to post
Share on other sites

Ok. So let start from the beginning.

When you unpack and run the easy example from the first post of this topic, does  it work?

Share this post


Link to post
Share on other sites

My friends can use this code (use COM - without registering Dll):

MsgBox(0, 'Result', _ExtractTextCOM("sample.docx", False))

Func _ExtractTextCOM($sFilename, $bProperties = False)
    Local $hXd2tx = DllOpen(@ScriptDir & "\xd2txcom" & (@AutoItX64 ? '_64' : '') & ".dll")
    If @error Then Return SetError(1, '', '')
    Local $oXd2tx = ObjCreate('{4ECE8E8A-BCC2-4709-BCAE-264210DF321B}', '{EB26F494-4E90-4432-9BA6-C6D9CDEE25C4}', $hXd2tx)
    Return $oXd2tx.ExtractText($sFilename, $bProperties)
EndFunc

 

Edited by moimon
Wrong Code

Share this post


Link to post
Share on other sites

@jcpetu:

Unfortunately no idea.

It works perfect on my side.

What about bit version of autoit.exe?

Dll is X86.

So it shoult be run using X86 version of Autoit or compiled as X86.

What about Scite settings? Don't you prefer X64 Autoit here?

Good Luck! On my side unfortunately no other idea to make it work on your enviroment..

Share this post


Link to post
Share on other sites

@jcpetu:
I think that i solved your trouble. :)
You probably don't have installed Microsoft Visual C++ 2010 Redistributable package for x86, which is necessary for whole Xdoc2Txt project.
............
So try to install it, for example from Here.
Then the x86 version of the DLL and script should work i hope.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Pured
      I am looking to create a script which refreshes/reads a webpage every few seconds. My goal is to see if the page has changed, then I will send myself a notification that the webpage has been updated.
       
      However, rather than downloading the entire webpage every single time, is there a way to check when the webpage last updated?
       
      If not, is there away to partially download/read html source until a specific tag is hit?
       
      Goal: I would like to increase my poll rate and not excessively waste data.
    • By Mr_Microphone
      Alright, I may be an idiot.
      Three years ago, I wrote a program that pushed component information to a secure site via their API. I went back to add some attributes and (here's the idiot part) ended up losing the  source code and my modified code does not quite work. I have the compiled version that works minus the new attributes, so I know that their system has not changed. I stripped the larger program down from 3,000 lines to the part that is broken, but I am stumped. This was one of my first scripts, so it heavily leverages examples and isn't as pretty as I'd like it to be.
      Be gentle. 
      The program / script creates a new records as expected, but for some reason, I cannot access information in the response, which I need for a later step.
      I use Charles, a web debugging proxy tool so I can see the request and the response and both are as expected. Also, when I write to log file, the JSON reply is exactly what I expect and need, but when I try to do anything with the http body, it seems to be blank. 
      Here is the script minus  the URL and token:
      #include <Array.au3> #include <Curl.au3> #include <MsgBoxConstants.au3> #include <json.au3>  ; this was added as an alternate way to read the data Global $WM_serial_number = "WM20745001" Global $wm_component_status_id = "10" Global $wm_manufacturer ="Multi-Tech" Global $wm_model = "MTR-LAT1-B07" Global $cellular_carrier_id = "3" Global $iccid_esn = "89010303300012345678" Global $ip_address = "192.168.2.11" Global $NewIDNumber     Local $Curl = Curl_Easy_Init()     Local $Html = $Curl ; any number as identify     Local $Header = $Curl + 1 ; any number as identify     Local $HtmlFile = "cURL_Request.html"     Local $File = FileOpen($HtmlFile, 2 + 16)     Local $Slist = Curl_Slist_Append(0, "content-type: multipart/form-data; boundary=---011000010111000001101001")     $Slist = Curl_Slist_Append($Slist, "authorization: Token token=" & $Token)     Curl_Easy_Setopt($Curl, $CURLOPT_PROXY, "127.0.0.1") ; needed to use Charles web debugging proxy     Curl_Easy_Setopt($Curl, $CURLOPT_PROXYPORT, 8888) ; needed to use Charles     Curl_Easy_Setopt($Curl, $CURLOPT_HTTPHEADER, $Slist) ;     Curl_Easy_Setopt($Curl, $CURLOPT_URL, $Server & "wireless_module" & "s")     Curl_Easy_Setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 0)     Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30)     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Html)     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_FileWriteCallback())     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $File)     Local $HttpPost = ""     Local $LastItem = ""         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[serial_number]", $CURLFORM_COPYCONTENTS, $WM_serial_number, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[component_status_id]", $CURLFORM_COPYCONTENTS, $wm_component_status_id, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[manufacturer]", $CURLFORM_COPYCONTENTS, $wm_manufacturer, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[model]", $CURLFORM_COPYCONTENTS, $wm_model, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[cellular_carrier_id]", $CURLFORM_COPYCONTENTS, $cellular_carrier_id, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[iccid_esn]", $CURLFORM_COPYCONTENTS, $iccid_esn, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[ip_address]", $CURLFORM_COPYCONTENTS, $ip_address, $CURLFORM_END)         ; submit         Curl_Easy_Setopt($Curl, $CURLOPT_HTTPPOST, $HttpPost)         Local $Code = Curl_Easy_Perform($Curl)         If $Code = $CURLE_OK Then         ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF)         ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF)         MsgBox(0, 'Html', BinaryToString(Curl_Data_Get($Html))) ; this is something I threw in for debugging, expecting to see SOMETHING. Returns nothing         MsgBox(0, 'Header', BinaryToString(Curl_Data_Get($Header))) ; this is something I threw in for debugging, expecting to see SOMETHING. Returns nothing         Local $response = Curl_Easy_GetInfo($Curl, $CURLINFO_RESPONSE_CODE)             If $response = "409" Then $response = "Failed due to a conflict."             If $response = "200" Then $response = "Was NOT created."             If $response = "201" Then $response = "Was created."             ; read the ID that was assigned and store it         $NewIDNumber = StringRight(StringLeft(BinaryToString(Curl_Data_Get($Html)), 10), 4) ; this DID work, but now it doesn't. An old compiled version still works ;~         Global $JsonObject = json_decode($Html); another debugging attempt. Did not use json functions previously and the program worked without it. ;~         Global $NewIDNumber = json_get($JsonObject, '.id')         ConsoleWrite(@CRLF &'! id:' & $NewIDNumber & @CRLF & @CRLF)    ; debugging feedback         MsgBox(0, $response, $wm_serial_number & " new ID = " & $NewIDNumber); debugging feedback         If $Code <> $CURLE_OK Then ConsoleWrite(Curl_Easy_StrError($Code) & @LF)             Local $Data = BinaryToString(Curl_Data_Get($Curl))             Curl_Easy_Cleanup($Curl)             Curl_Data_Cleanup($Curl)             Curl_Data_Cleanup($Header)             Curl_Data_Cleanup($Html)             Curl_FormFree($HttpPost)             Curl_slist_free_all($Slist)             curl_easy_reset($Curl)             FileClose($File)             ConsoleWrite(@LF)         EndIf  This is the captured request (minus the host and token)
      POST /api/v2/wireless_modules HTTP/1.1 Host: api. Accept: */* authorization: Token token= Content-Length: 942 Expect: 100-continue content-type: multipart/form-data; boundary=---011000010111000001101001; boundary=------------------------9adb0d87c7ea5061 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[serial_number]" WM20745001 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[component_status_id]" 10 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[manufacturer]" Multi-Tech --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[model]" MTR-LAT1-B07 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[cellular_carrier_id]" 3 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[iccid_esn]" 89010303300012345678 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[ip_address]" 192.168.2.11 --------------------------9adb0d87c7ea5061-- and the captured response
      HTTP/1.1 201 Created Date: Sun, 04 Apr 2021 00:12:18 GMT Server: Apache Cache-Control: max-age=0, private, must-revalidate Access-Control-Allow-Origin: not-allowed Vary: Accept-Encoding Access-Control-Max-Age: 1728000 X-XSS-Protection: 1; mode=block X-Request-Id: 71cfcf36-6020-48a6-a822-d2b393a27b69 Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: PUT, OPTIONS, GET, POST ETag: W/"25d97fe8a9387cb4b9029a9e62b0bfa2" X-Frame-Options: SAMEORIGIN, SAMEORIGIN X-Runtime: 0.344005 X-Content-Type-Options: nosniff Access-Control-Request-Method: * X-Powered-By: Phusion Passenger 5.2.1 Strict-Transport-Security: max-age=63072000; includeSubDomains; preload Location: /wireless_modules/3195 Status: 201 Created Connection: close Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8 X-Charles-Received-Continue: HTTP/1.1 100 Continue {"id":3195,"model":"MTR-LAT1-B07","serial_number":"WM20745001","manufacturer":"Multi-Tech","mfg_date":null,"iccid_esn":"89010303300012345678","ip_address":"192.168.2.11","purchase_order":null,"supplier":null,"cellular_carrier_id":3,"component_status_id":10,"component_status":{"id":10,"name":"Hold","description":"Available- Held for specific use"},"custom_attributes":[{"name":"Deactivated","type":"Boolean","value":false},{"name":"Port 3001","type":"Boolean","value":false}],"comments":[]}  
      Also attached is the log file. I need to read the id value. Clearly, it is arriving back to cURL, since it is being written out to the log, but I cannot seem to get to it within the code. 
      It is established that I may be an idiot, but this idiot has wasted days in non-billable hours trying to figure out what should be a simple glitch.
      Help???
       
      cURL_Request.html
    • By Hermes
      I have an html table that displays data along with an excel spreadsheet that has the same data as the html table. I am wanting to only match the Title column in my html table with the Title column in my Excel spreadsheet. If the titles match, click on the Edit hyperlink and continue to loop to next row. The issue I'm experience is its not matching correctly. So far  i've written the codes below:
      <table border="1" class="test"> <tr> <th> UniqueID</th> <th> Title</th> <th> UserID</th> <th> Address</th> <th> Gender </th> </tr> <tr> <td> 1 </td> <td> Title1 </td> <td> 12345 </td> <td> Manila </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5"> <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 2 </td> <td> Title2 </td> <td> 67891 </td> <td> Valenzuela </td> <td> <span> Female </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 3 </td> <td> Title3 </td> <td> 88888 </td> <td> Ohio </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 4 </td> <td> Title4 </td> <td> 77777 </td> <td> California </td> <td> <span> Female </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 5 </td> <td> Title5 </td> <td> 33333 </td> <td> Arizona </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> </table> #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "Excel.au3" #Include "_HtmlTable2Array.au3" #Include "Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "index.html") Sleep(6000) Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, "test.xlsx") ; Get the table element $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='test']") ; Retrieve HTML $sHTML = _WD_ElementAction($sSession, $sElement, "Property", "outerHTML") ;Local $aTable = _HtmlTableGetWriteToArray($sHTML) Local $aArray1 = _Excel_RangeRead($oWorkbook,1,$oWorkbook.ActiveSheet.Usedrange.Columns("B:B")) Local $aArray2 = _HtmlTableGetWriteToArray($sHTML) ;_ArrayDisplay($aArray1) ;_ArrayDisplay($aArray2) For $i = UBound($aArray1) - 1 To 0 step - 1 For $j = UBound($aArray2) - 1 to 0 step - 1 If $aArray1[$i][1] == $aArray2[$j][1] Then _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]") $test1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]") _WD_ElementAction($sSession, $test1, 'click') ;_ArrayDisplay($aArray1) ;_ArrayDelete($aArray1 , $i) ;exitloop EndIf Next Next _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome Would appreciate if anyone can provide tips, or point me in the right direction in doing it.
       
      test.xlsx
    • By Zaoka
      I'm trying to create script that would login on my SAP WEBI "web page" and replace some uploaded excel files. But i'm having problem on even the log in.
      These are user fill elements with Firefox Inspector
      <input type="text" id="_id0:logon:CMS" name="_id0:logon:CMS"> <input type="text" id="_id0:logon:USERNAME" name="_id0:logon:USERNAME"> <input type="password" id="_id0:logon:PASSWORD" name="_id0:logon:PASSWORD"> LogOnButton
      <input type="submit" id="_id0:logon:logonButton" value="Log On" class="logonButtonNoHover logon_button_no_hover" onmouseover="this.className = 'logonButtonHover logon_button_hover';" onmouseout="this.className = 'logonButtonNoHover logon_button_no_hover';">  
       
      My example, I tried _IEGetObjByName and _IEGetObjById but the script only open page but will not even fill out the form
        #include <IE.au3> Call("signIn") Func signIn() Global $oIE = _IECreate("http://192.xxx.xxx.xx:xxx/BOE/BI") Sleep (5000) Local $server = _IEGetObjByName($oIE, "_id0:logon:CMS") Local $username = _IEGetObjByName($oIE, "_id0:logon:USERNAME") Local $password = _IEGetObjByName($oIE, "_id0:logon:PASSWORD") Local $button = _IEGetObjById($oIE, "_id0:logon:logonButton") _IEFormElementSetValue($server, "TestServer:1000") _IEFormElementSetValue($username, "MyUserName") _IEFormElementSetValue($password, "MyPass") ; THIS PART ABOUT BUTTON CLICK I DONT UNDERSTAND AT ALL $sSelector = "body > div:nth-of-type(2) > div > div:nth-of-type(3) > div > table > tbody > tr > td > table > tbody > tr > td > table > tbody > tr:nth-of-type(1) > td > div > div:nth-of-type(1) > form > div:nth-of-type(5) > button" $signInUC = $oIE.document.QuerySelector($sSelector) _IEAction($signInUC, "click") EndFunc ;==>signIn  
      I would be very grateful for any help
    • By amosrinat
      Hi,
      i have an AutoIT script that sends emails with two embedded images.
      When users get the email they don't see the images. How should I fix my code?
      Thank you for your support,
      Amos
      Func fSendMail() $TemplateName = StringRegExpReplace($Template, "^.*\\|\..*$", "") $SmtpServer = "smtp.**.com" $FromName = "do-not-reply@*********" $FromAddress = "do-not-reply@******" $ToAddress = $MG1_Mgr & ";"& $Owner $Subject = "ACTION REQUIRED - " & $TemplateName $Body = $sBody5 $IPPort = 25 $ssl = 0 Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = fINetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $IPPort, $ssl) If @error Then MyErrFunc() EndIf EndFunc;fSendMail Func fINetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $IPPort = 25, $ssl = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 Then $IPPort = 25 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort $objEmail.Configuration.Fields.Update $objEmail.Fields.Update ;$objEmail.Send **************** If @error Then MyErrFunc() EndIf $objEmail = "" EndFunc;fINetSmtpMailCom  
×
×
  • Create New...