Sign in to follow this  
Followers 0
water

Update the Word UDF that comes with AutoIt (former WordEX thread)

68 posts in this topic

#1 ·  Posted (edited)

New versions of Microsoft Office have been released since the last changes were made to the Word UDF. New file types and new functions need to be supported.
This updated version supports Word 2003 up to Word 2010. The latest version of AutoIt is needed to use the latest COM error handler.
Some rarely used functionality has been removed, new functions have and will be added.
The attached PDF shows what's different between Word.au3 and WordEX.au3
You'll find examples for every function ready to run.

Please tell me what you think, about missing functions etc.

2012-07-31 - Version 1.0 - Downloads: 89

First release


2012-08-23 - Version 1.1 - Downloads: 26

New Functions:
  • _Word_DocTableRead: Reads a Word table into a 2D-array
  • _Word_DocTableWrite: Writes a 1D or 2D-array to a Word table

Removed Functions:

  • _Word_MacroRun: Just called the Run method, nothing else, hence removed

 

2012-08-26 - Version 1.2 - Downloads: 277

New Functions:
  • _Word_DocFind: Run or repeat a find operation

 

2012-12-29 - Version 1.3 - Downloads: 937

General:
  • Enhanced error checking
  • Enhanced documentation

New Functions:

  • _Word_DocExport: Exports the document or a range as PDF or XPS

Changed Functions:

  • _Word_Create: Parameter $bForceNew added to create a new instance even if another already exists
  • _Word_DocClose: Defaults for parameters $iSaveChanges and $iOriginalFormat changed to minimize need for user intervention
  • _Word_DocLinkAdd: Default for parameters $oAnchor, $sAddress, $sSubAddress, $sScreenTip, $sTextToDisplay and $sTarget changed from "" or 0 to keyword Default
  • _Word_DocLinkGet: Default for parameter $iIndex changed from -1 to keyword Default

Removed Functions:

  • Unneeded helper functions: CentimetersToPoints, InchesToPoints, LinesToPoints, PicasToPoints, PointsToCentimeters, PointsToInches, PointsToLines, PointsToPicas

 

2013-07-28 - This download page is no longer needed - the rewritten Word UDF is now part of the latest beta version!

Edited by water
2 people like 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



#2 ·  Posted (edited)

To do:

  • _Word_DocTableFormat: Format a table, columns or rows
To check:
  • Formatting of a range (font, style ...)
  • Shapes
  • Lists
Done:
  • _Word_DocTableWrite: Write a 1D or 2D array to a Word table
  • _Word_DocTableRead: Read the content of a Word table to an array
  • _Word_DocFind: Extended search function
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

Would be nice to see more functions included, f.ex to add shapes.

In that relation, it would be real nice to download and insert all the many many enumerations that Word/Office uses, into a UDF, and possibly also with auto-complete in Scite. (that's my wish for serious Office COM work)

For expansion of this, would you accept change proposals, or just requests ?


I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites

I will have a look at shapes. Which functionality do you need?

Enumerations:

I don't think it is sensible to include all enumerations - the list would be too long. WordEXConstants contains all enumerations referenced by a function of the WordEX UDF. I think auto-complete in SciTE isn't very realistic at the moment. But MSDN isn't far away.

I accept all kinds of change proposals, requests ... whatever. You post what you'd like to see and then we discuss if it makes sense to include it ^_^


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

Version 1.1 has been released!

Have fun testing!


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

@water

Thanks for the UDF, particularly for the new _Word_DocRangeSet.

Look forward to your future releases.

Regards

Ajit

Share this post


Link to post
Share on other sites

Is there anything you would like to see in the Word UDF?


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 will have a look at shapes. Which functionality do you need?

I came to this yesterday because I needed to create a test document where placement of shapes on the page was essential (for a test pattern used at work). I gave up the menu hell in Word and ended up programming a macro for it. But it would have been nice to use AutoIT for the purpose, since the job was perfect for scripting.

I think the basic shapes should be enough, although actually there are only two: shape and inlineshape. In your script you only have inlineshape. Difference is that shape hovers over text, and is page-related. inlineshape is text-related, like a char.

There are some 150 different types (according to enumeration), but for most 5-10 basic shapes are used.

Something like

$myShape = _Word_Shape_Add($myDoc, $WdShapeTypeRectangle, 100, 120, 10, 10)
_Word_Shape_Set_Color($myShape, $WdWhite, $WdBlack)

There are MANY options to shapes, so I will have to look a bit deeper into this matter. There are also some definitions to do, f.ex measurements in points/inch/mm/cm/.. ? Insert in document or range ?

Enumerations:

I don't think it is sensible to include all enumerations - the list would be too long. WordEXConstants contains all enumerations referenced by a function of the WordEX UDF. I think auto-complete in SciTE isn't very realistic at the moment. But MSDN isn't far away.

Yes, you are probably right. I actually did not see you already included many of them, my bad.

I accept all kinds of change proposals, requests ... whatever. You post what you'd like to see and then we discuss if it makes sense to include it ^_^

Is discussion about your script HERE or in the general forum ? I mean, Example scripts is for showing your script, not requesting features - or ? I am in doubt about forum rules on that point, who/where do I ask ?

But anyway, a few things:

  • Shape and InlineShape
  • Adding styles to new documents (do not have to be globally stored), and modifying style definitions. I tried to do that myself and failed badly.
  • Working with variables (essentially metadata, MSWord allows up to 65280 unicode chars per var.), and changing document properties
  • Tables (you already have that in the pipeline)

Think this will be a great UDF :)


I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites

I think the Word UDF isn't and can never be one of the UDFs that isolates the user completely from the object model. He will have to cope with methods and properties.

The UDF will only have basic functions - everything else has to be done by the user (see the example script _Word_RangeSet.au3 where the UDF makes handling the range a bit easier, but what to do with the range is up to the user and needs some knowledge of the object model).

Shapes:

I will have a look at shapes and if it makes sense to add them to the UDF. The functions should be useful to a lot of people.

Styles:

Maybe later. For now I think we should add the simple things

Variables, document properties:

We removed functions to get/set properties of a document or the Word application because it is only a single line when directly accessing COM

If you have a problem you need to solve post here so we can discuss if this can be solved with a UDF function.


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

@water,

Would it be possible to have a function to search for a word which then highlights the word (just like Ctrl+F in word) the first occurrence of the word.

_Word_DocFindReplace just replaces the word in one go.

Also if possible the GoTo functions (Ctrl+G) like GoTo Line, Page, Section (i am not very sure if _Word_DocRangeSet can accomplish some of these tasks).

Also if file menu show/hide, word window size and placement of window could be added.

Regards,

Ajit

Share this post


Link to post
Share on other sites

Hi Ajit,

an extended search function is in the pipeline. You will be able to step through the search results and do whatever you need to do with each result.

_Word_DocRangeSet should be able to do what you need (I hope). Just use the correct units from the wdUnit enumeration.

I'm not sure if window handling (size, position) should be part of the Word UDF. Because window handling is one of the core duties of AutoIt itself, right?

Regards

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

Water,

Thanks for the quick reply.

Look forward to the extended search function. Will be back with more queries.

Regards,

Ajit

Share this post


Link to post
Share on other sites

I have an extended find function now that lets you search forward and backward in a specified range.

It doesn't let you wrap the search though. That means you can't continue to search at the beginning of the range when you have reached the end and vice versa.

Might this be a problem for someone?


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

Version 1.2 has been released!

Extended Find function (_Word_DocFind) added!

Have fun testing!


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

Water,

Thanks for _Word_DocFind. Got to play with it.

Regards

Ajit

Share this post


Link to post
Share on other sites

176 downloads of the latest version - but no error reports, no questions, no complaints :think:

Do you think the UDF is already good enough to replace the Word UDF that comes with AutoIt?


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

202 downloads of the latest version - but no error reports, no questions, no complaints :think:

Do you think the UDF is already good enough to replace the Word UDF that comes with AutoIt?


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

Thanks, glad you like the enhanced UDF :D


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

water,

I've use the old _WordDocPropertySet in some of my programs now because of the variety of MS Word versions the programs apply to I'm using the WordEX 1.2 UDF. Is there any reason why I can't include WordEX.au3 and Word.au3 both in order to give me access to _WordDocPropertySet? It doesn't seem to work for me when I use both.

I see that the equivalent has been removed from your program along with _WordDocPropertySet . Does this mean that when/if WordEX 1.2 UDF is adopted these the removed functions will no longer be available?

Thanking you for any information,

jury

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0

  • Similar Content

    • Neonovaz
      By Neonovaz
      Hello
       
      Is there anyway to store word documents in Autoit GUI? For example I have a instruction sheet that I want to bundle up with the exe.

      So a user simply clicks the icon and the stored document will launch  (Something like how you can add objects like excel sheets in word documents )

      (I Know we can launch word files from script directory)

       
    • 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)