MrCheese

Merge word documents

27 posts in this topic

Hi Guys,

Firstly, thanks for your  help in the past.

I have a new activity I need to accomplish.

In summary:

* need to read a cell in excel (containing a file name)

* open the file name in word (as its a word document

*copy the word document

*paste the word document into the master document

*read next cell in excel

... and repeat until you reach the bottom of the column.

 

I can read cells open workbooks etc.

But as far as copying and pasting in word - where is the best place to start, and what functions should I be looking at. Or even if autoit is the right system to use?

Thanks

 

 

 

Share this post


Link to post
Share on other sites



Do you really need to copy all word documents into a master document?
Or could you just add "links" to the master document. When opened the master document reads all linked documents and displays them as a single big document.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi Water,

That would work, providing that you could then save that one master document as a whole document in its own right.

Basically, I have ~ 120 different module documents.

and will have ~ 40 master documents, which are made up of different module documents.

The differences are captured in an excel matrix, utilising a standardised naming conventions for the module file names.

Each master document will need to be distributed (as a whole) for review and feedback, ideally in Doc or docx format to allow tracked changes etc.

Does that help?

Really appreciate your help on this one.

I read ages ago that there is an insert function somewhere, but that's all I can recall.

Share this post


Link to post
Share on other sites

Use _Word_DocRangeSet to set the insertion mark to the desired location.
The returned range object then is used to insert the file

$oRange.InsertFile("C:\temp\insert.docx")

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

how do I best jump from inserting one document, then jumping to the bottom of that newly inserted document, to the inserting another?

is there a _word_docrangeset to jump to the bottom?

Share this post


Link to post
Share on other sites

Sure:

_Word_DocRangeSet($oDoc, -2)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Excellent.

I'll work on some code over the next 24 hours.

Thanks for your help so far.

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I'm not sure why, but the word documents aren't opening.

See the attached zip for all the dummy test files I'm using.

i wanted to create a fresh document, add the subdocuments and save it as a different file name at the end.

 

Ideally wanted to add each document by reading across the one row, then move to the next row.

Since that didn't seem to work, I transposed the data to then read down the column, then start on the next column.

#include <MsgBoxConstants.au3>
#include <Word.au3>
;~ #include <Array.au3>
#include <Excel.au3>
;~ #include <Timers.au3>
;~ #include <Date.au3>


;----------------------- CHANGE BELOW --------------------;
$nExcelBook = "matrix"
$cBookLocalName = @ScriptDir & "\Test\" & $nExcelBook & ".xlsx"
$version = "v1"
$vpn = False
$onerow = True
;----------------------- CHANGE ABOVE --------------------;
$columnstart = "A"
$rowstart = 4
$oWorkbook1 = 0

$eComment = "H"

OpenExcel()

;Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Test\Test.docx", Default, Default, True)

;sleep(5000)
$run = 0
While 1
    $run = $run + 1
    $column = $columnstart
    $row = $rowstart
    if $run = 2 then $column = "B"
    Local $oRange, $oWord = _Word_Create()
    $eAreaName = _Excel_RangeRead($oWorkbook1, Default, $column & $row)
    If $eAreaName = "" Then
        _Excel_RangeWrite($oWorkbook1, $oWorkbook1.ActiveSheet, "Dataload completed", $eComment & $row)
        ExitLoop
    EndIf
    _Word_DocAdd($oWord)
    ; new word document
    ;insertdoc()
    _Word_DocRangeSet($oWord, -2)
    $oRange.InsertFile(@ScriptDir & "\Test\" & $eAreaName & ".docx")
    ;$column = $column + 1
    While 1
        $row = $row + 1
        $eAreaName = _Excel_RangeRead($oWorkbook1, Default, $column & $row)
        If $eAreaName = "" Then
            _Excel_RangeWrite($oWorkbook1, $oWorkbook1.ActiveSheet, "Row Completed", $eComment & $row)
            ExitLoop
        EndIf
        _Word_DocRangeSet($oWord, -2)
        $oRange.InsertFile(@ScriptDir & "\Test\" & $eAreaName & ".docx")
        ;insertdoc()
        ;$row = $row + 1
        ;$column = $column + 1
    WEnd
    $eAreaName = _Excel_RangeRead($oWorkbook1, Default, 1 & $row)
    _Word_DocSaveAs($oWord, @ScriptDir & "\Test\Final.doc");" & $eAreaName & ".doc")
    $rowcomplete = True
    If $onerow = True Then
        ExitLoop
    EndIf
    ;$row = $row + 1
WEnd

MsgBox(0, "Completed", "Document creator has completed.")

Func insertdoc()

EndFunc   ;==>insertdoc

Func OpenExcel()
    ; Create application object and open an example workbook
    _Excel_BookClose($oWorkbook1)
    Global $oExcel = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open Workbook 1
    Global $oWorkbook1 = _Excel_BookOpen($oExcel, $cBookLocalName)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error opening workbook '" & @ScriptDir & "Book1.xlsx'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf
EndFunc   ;==>OpenExcel

 

Test.zip

Share this post


Link to post
Share on other sites

The following script works for me. Please copy all files into directory C:\temp\Merge_Word

Test2.zip


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

awesome.. so simple right?

However, can I make it read across columns in excel, and then say at the end (say column M), jump to the next row?

and how could i commence reading/inserting from column B?

and lastly, how do I insert a page break after each insertion?

 

not sure what : $wdPageBreak   would refer to?

$oRange.InsertBreak($wdPageBreak)

 

Share this post


Link to post
Share on other sites

Something like this?
$wdPageBreak is one of the Word enumerations you can find in the WordConstants.au3 (an include which gets called by Word.au3).

Test.zip

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

its getting there!! thanks for your help.

One thing, can I have it so row 1 is its own document that is saved according to its file name located in the last cell? (column D)

and then row 2 is its own document... row 3 is its own etc.

Test (2).zip

Edited by MrCheese

Share this post


Link to post
Share on other sites

That's easy:

#include <Word.au3>
#include <Excel.au3>

Global $oExcel = _Excel_Open(False)
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx")
Global $aDocuments = _Excel_RangeRead($oWorkbook)
_Excel_Close($oExcel, False)
Global $oWord = _Word_Create()
Global $oDocMaster, $oDoc, $i, $j
For $i = 0 To UBound($aDocuments, 1) - 1
    $oDocMaster = _Word_DocAdd($oWord) ; Start a new document for every row
    Global $oRange = _Word_DocRangeSet($oDocMaster, -1)
    For $j = 0 To UBound($aDocuments, 2) - 2 ; last element of the row holds the path of $oDocMaster
        If $aDocuments[$i][$j] <> "" Then
            $oRange.InsertFile($aDocuments[$i][$j])
            $oRange = _Word_DocRangeSet($oDocMaster, -2)
            $oRange.InsertBreak($WdPageBreak)
        EndIf
    Next
    ConsoleWrite($aDocuments[$i][UBound($aDocuments, 2) - 1] & @CRLF)
    _Word_DocSaveAs($oDocMaster, $aDocuments[$i][UBound($aDocuments, 2) - 1], $WdFormatDocumentDefault) ; Save master document
    ConsoleWrite(@error & @CRLF)
    _Word_DocClose($oDocMaster) ; Close document
Next
_Word_Quit($oWord)

N.B. The Excel file needs to hold the full path to the inptu and output Word document e.g. C:\temp\Test1.docx


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

hi,

thanks for that :)

unfortunately i'm getting a error on the insert file function:

"C:\temp\wordmerge_v3.au3" (15) : ==> The requested action with this object has failed.:
$oRange.InsertFile($aDocuments[$i][$j])
$oRange^ ERROR

 

as you can tell in the data load file the names contain the file path of both the inserting and saving.

Any ideas?

Thanks again.

#include <Word.au3>
#include <Excel.au3>

Global $oExcel = _Excel_Open(False)
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx")
Global $aDocuments = _Excel_RangeRead($oWorkbook)
_Excel_Close($oExcel, False)
Global $oWord = _Word_Create()
Global $oDocMaster, $oDoc, $i, $j
For $i = 0 To UBound($aDocuments, 1) - 1
    $oDocMaster = _Word_DocAdd($oWord) ; Start a new document for every row
    Global $oRange = _Word_DocRangeSet($oDocMaster, -1)
    For $j = 0 To UBound($aDocuments, 2) - 2 ; last element of the row holds the path of $oDocMaster
        If $aDocuments[$i][$j] <> "" Then
            $oRange.InsertFile($aDocuments[$i][$j])
            $oRange = _Word_DocRangeSet($oDocMaster, -2)
            $oRange.InsertBreak($WdPageBreak)
        EndIf
    Next
    ConsoleWrite($aDocuments[$i][UBound($aDocuments, 2) - 1] & @CRLF)
    _Word_DocSaveAs($oDocMaster, $aDocuments[$i][UBound($aDocuments, 2) - 1], $WdFormatDocumentDefault) ; Save master document
    ConsoleWrite(@error & @CRLF)
    _Word_DocClose($oDocMaster) ; Close document
Next
_Word_Quit($oWord)

wordmerge_v3.au3

dataload2.xlsx

Edited by MrCheese

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Does this work for you? It ignores files which do not exist:

#include <Word.au3>
#include <Excel.au3>

Global $oExcel = _Excel_Open(False)
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\dataload2.xlsx")
Global $aDocuments = _Excel_RangeRead($oWorkbook)
_Excel_Close($oExcel, False)
Global $oWord = _Word_Create()
Global $oDocMaster, $oDoc, $i, $j
For $i = 0 To UBound($aDocuments, 1) - 1
    $oDocMaster = _Word_DocAdd($oWord) ; Start a new document for every row
    Global $oRange = _Word_DocRangeSet($oDocMaster, -1)
    For $j = 0 To UBound($aDocuments, 2) - 2 ; last element of the row holds the path of $oDocMaster
        If $aDocuments[$i][$j] <> "" And FileExists($aDocuments[$i][$j]) Then
            $oRange.InsertFile($aDocuments[$i][$j])
            $oRange = _Word_DocRangeSet($oDocMaster, -2)
            $oRange.InsertBreak($WdPageBreak)
        EndIf
    Next
    _Word_DocSaveAs($oDocMaster, $aDocuments[$i][UBound($aDocuments, 2) - 1], $WdFormatDocumentDefault) ; Save master document
    _Word_DocClose($oDocMaster) ; Close document
Next
_Word_Quit($oWord)

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Another question:
We now have an empty page at the end of the master document. Should this empty page be removed?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

if it can be removed easily then yes, but its okay if not.

awesome so far!

ill run it a few times and see how it goes.

Share this post


Link to post
Share on other sites

This version deletes the last (empty) page:

#include <Word.au3>
#include <Excel.au3>

Global $oExcel = _Excel_Open(False)
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\dataload2.xlsx")
Global $aDocuments = _Excel_RangeRead($oWorkbook)
_Excel_Close($oExcel, False)
Global $oWord = _Word_Create()
Global $oDocMaster, $oDoc, $i, $j, $oRange
For $i = 0 To UBound($aDocuments, 1) - 1
    $oDocMaster = _Word_DocAdd($oWord) ; Start a new document for every row
    $oRange = _Word_DocRangeSet($oDocMaster, -1)
    For $j = 0 To UBound($aDocuments, 2) - 2 ; last element of the row holds the path of $oDocMaster
        If $aDocuments[$i][$j] <> "" And FileExists($aDocuments[$i][$j]) Then
            $oRange.InsertFile($aDocuments[$i][$j])
            $oRange = _Word_DocRangeSet($oDocMaster, -2)
            $oRange.InsertBreak($WdPageBreak)
        EndIf
    Next
    ; Go to the end of the document and delete the empty page
    $oRange = _Word_DocRangeSet($oDocMaster, -2, $wdCharacter, -3)
    $oRange.Delete
    ; Save and close master document
    _Word_DocSaveAs($oDocMaster, $aDocuments[$i][UBound($aDocuments, 2) - 1], $WdFormatDocumentDefault)
    _Word_DocClose($oDocMaster)
Next
_Word_Quit($oWord)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

OK

so in the excel book, i added a column at the start which contained the names of some "base" document (title page, contents, revisions etc). (doc attached).

but now the cpu cycles up, the autoit takes much longer to complete and no output documents are found :(:( 

i did have blank cells, but I removed them as it wasn't working; but even after removal its not working.

also i noticed all my documents are .doc, and not docx. does this cause a problem?

dataload2.xlsx

NWoW-Deliverable-Template-Division-WS.doc

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

  • Similar Content

    • Jury
      By Jury
      I've failed to find an example of _Word_DocFindReplace which searches for formatted text (I'm looking for stand alone paragraph marks that are formatted other than normal i.e. Bold Italic, Underlined). 
      The reason being that when converting a Word document to html one of the main problems in the results is that a stand alone paragraph mark is converted to an html space that retains the formatting ...>&nbsp;<... thus showing up as a underline _  in a browser when it should be blank.  I've played around with the script and got it to at least un-bold  the first paragraph mark regardless if it was bold or not but I'd like to clear all formatting from any stand alone paragraph marks in the whole document.  Below is what I've done so far (not much more than in the help file I'm afraid) .  Way down at the bottom of the _Word_DocFindReplace  help  text is this parameter but without any examples to be found :
      $bFormat   [optional] True to have the find operation locate formatting in addition to or instead of the find text (default = False) #include <MsgBoxConstants.au3> #include <Word.au3> $processing = @MyDocumentsDir & '\AutoIt_code\getter\processing\' Global $oWord = _Word_Create() Global $sTestfile = $processing & "Testing.docx" ConsoleWrite($sTestfile & @CRLF) Global $oDoc = _Word_DocOpen($oWord, $sTestfile) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error opening file = '" & $sTestfile & "'" & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound = _Word_DocFind($oDoc, "^p", Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating paragraph control character in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound.Bold = False If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error inserting text after the paragraph control character in the document." & @CRLF & "@error = " & @error & _ ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Paragraph control character successfully replaced." & @CRLF & _ "Text inserted in paragraph 2.")  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I am working on a little script, which takes some data from a SQLite DB and should create a sort of report, inserting rows in a Word Document... I arrived at the point of:
      _Word_DocTableWrite() and, I don't know how to set the range parameter? What does that specify? 
      Thanks a lot for the help
      EDIT:
      Managed to write a table in the Word document, but now I get an error when I save the document with _Word_DocSaveAs(), with error 2.
      Which are possible causes? Thanks a lot, again
      EDIT 2:
      ... And, how can I set a border to the table? Maybe, with a sort of auto-formatting for text ( larger is the text, larger is the height/width of the table's cell ).
      Thanks  
      EDIT 3 ( bug ):
      Including the parameter $WdSaveChanges in the function _Word_DocSaveAs(), a save dialog box appears, and it should not do it, as it's written in the MSDN documentation:
      wdSaveChanges -1 Save pending changes automatically without prompting the user. Thanks again for everyone will answer to me  
    • anthonyjr2
      By anthonyjr2
      I'm using the Word UDF for the first time, and I'm having some trouble with _Word_DocFind(). There isn't really much talk around the forums about this so it's hard to find any support on the issue I'm having. Here's my code:
      #include <Word.au3> $listPath = @ScriptDir & "\AMCH OFFSET 042617.docx" $pWord = _Word_Create() $oWord = _Word_DocOpen($pWord, $listPath) Local $ctr = 0 Local $searchRange = _Word_DocFind($oWord, "Claim Number") If Not @error Then $ctr += 1 EndIf While ($searchRange <> 0) $searchRange = _Word_DocFind($oWord, "Claim Number", 0, $searchRange) If Not @error Then $ctr += 1 EndIf $searchRange.Select WEnd My problem is that it doesn't seem to find a match of the string on any page after the second. When I run the script, it just loops indefinitely on the second page. I can't post an example of the word document because it is medical data, but every page is basically the same and every page has the string I am looking for on it. Also I tried checking @error after doing a find and it is never set, so I don't think that's the problem.
    • Alin86
      By Alin86
      Hello, in my own design of small procedures, used to insert the ellipse notation in the GUI graphics, and let the arrow pointing to the little girl mouth position. I discovered that point to the gap region size is not fixed, first thought he had just set the angle, calculate the arc starting coordinates and end coordinates OK, then I found that I was wrong. The online search information, for a long time did not find the answer, only to the official website to help you, because I do not start.

      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <Array.au3> Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client $nPI = 3.1415926535897932384626433832795 $iAngle = 95 $iSpace = 50 $nX = 100 $nY = 200 $nWidth = 200 $nHeight = 100 $fStartAngle = $iAngle + $iSpace / 2 $fSweepAngle = 360 - $iSpace _GDIPlus_Startup() Local Const $iWidth = 600, $iHeight = 600 Local $hGUI = GUICreate("GDI+ UDF 示例", $iWidth, $iHeight) GUISetState(@SW_SHOW) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Local $hPen = _GDIPlus_PenCreate(0xFFFF8080, 1) Local $hImage = _GDIPlus_ImageLoadFromFile("g_8.png") _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 400, 100, 102, 278) _GDIPlus_GraphicsDrawArc($hGraphics, $nX, $nY, $nWidth, $nHeight, $fStartAngle, $fSweepAngle, $hPen) ; Local $a = $nWidth / 2 Local $b = $nHeight / 2 Local $c = Sqrt($a ^ 2 - $b ^ 2) Local $Coordinate[4] $Coordinate[0] = Sqrt($a ^ 2 * $b ^ 2 / ($a ^ 2 * Tan((360 - $iAngle - $iSpace / 2) * $nPI / 180) ^ 2 + $b ^ 2)) $Coordinate[1] = Tan((360 - $iAngle - $iSpace / 2) * $nPI / 180) * $Coordinate[0] ;_ArrayDisplay($Coordinate) If (360 - $iAngle - $iSpace / 2) >= 90 And (360 - $iAngle - $iSpace / 2) <= 270 Then $Coordinate[0] = -$Coordinate[0] If (360 - $iAngle - $iSpace / 2) >= 0 And (360 - $iAngle - $iSpace / 2) < 180 Then $Coordinate[1] = -$Coordinate[1] $Coordinate[0] = $nX + $a + $Coordinate[0] $Coordinate[1] = $nY + $b + $Coordinate[1] ;MouseMove($Coordinate[0], $Coordinate[1]) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_PenDispose($hPen) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI)
    • Duck
      By Duck
      I'm attempting to read each line of a word document and assign the line to a variable. Similarly to how you can read a line from a text file (.txt or .csv) using FileReadLine(). So far i have been unsuccessful in reading from a .doc/.docx file, nor have i found any documentation that has helped.

      In searching for a solution i did find a function to convert the word doc to a text file, however my script is for (PCI) auditing purposes and i do not want to create a new file on the HDD.  I have also read through the _Word UDF help files... Unless im not understanding the _Word UDF correctly, I did not see anything that functions similarly to the FileReadLine function.
      Any help/advice is greatly appreciated!  
       
      Here is what i have been attempting to do(doesn't work): 
       
      #include <file.au3> #include <Array.au3> #include <LuhnCheck.au3> #include <Excel.au3> #include <Word.au3> Global $sPath = 'C:\Users\' Global $filePath Global $pii = @ScriptDir & '\pii_CreditCard.csv' Global $filesArray = _FileListToArrayRec($sPath , '*.txt;*.csv;*.doc;*.docx;*.xls;*.xlsx',1,1,0,2) For $i = 1 to $filesArray[0] ;Loop through file extensions and add files to the fileArray ;Assign the position in the filesArray to filePath (filePath is set to full path in FileListToArrayRec) $filePath = $filesArray[$i] readFile($filePath) Next Func readFile($file) If StringInStr($file, '.txt') Or StringInStr($file, '.csv') Then ; .txt file readTxtFile($file) ElseIf StringInStr($file, '.doc') Then ; .doc & .docx files ;============================================== part that does not work========================= Local $oWord = _Word_Create() ;$openFile = FileOpen($file, 0); While 1 Local $line = FileReadLine(_Word_DocOpen($oWord, $file, Default, Default, True)) If @error = -1 Then ExitLoop ;lookForCreditCardNumbers($line) MsgBox(0,0, $line) WEnd FileClose($openFile) ;============================================== part that does not work========================== EndIf EndFunc Func readTxtFile($fileToOpen) $openFile = FileOpen($fileToOpen, 0); open file for reading and assing it to the openFile variable While 1 Local $line = FileReadLine($openFile) If @error = -1 Then ExitLoop lookForCreditCardNumbers($line) WEnd FileClose($openFile) EndFunc Func lookForCreditCardNumbers($evaluateString) $aResult = StringRegExp($evaluateString, '[4|5|3|6][0-9]{15}|[4|5|3|6][0-9]{3}[-| ][0-9]{4}[-| ][0-9]{4}[-| ][0-9]{4}', $STR_REGEXPARRAYMATCH) If Not @error Then Local $newString1 = StringReplace($aResult[0], ' ', '') ;remove spaces Local $newString2 = StringReplace($newString1, '-', '') ;remove dashes Local $bool = _LuhnValidate($newString2) ; Check possible CC number against the Luhn algorithm If $bool = 'True' Then Local $piiCSV = FileOpen($pii, 1) ;open text file for appending/writing, 1 FileWriteLine($piiCSV, $filePath & ', ' & $newString2) FileClose($piiCSV) EndIf EndIf EndFunc