Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: Automating Word with Perl

by jplindstrom (Monsignor)
on Oct 29, 2008 at 03:07 UTC ( [id://720141]=note: print w/replies, xml ) Need Help??

in reply to Re^2: Automating Word with Perl
in thread Automating Word with Perl

From your original question, I'm not sure why you would want to do that.

Why not start with a template Word file (with nice headers, footers, logos etc), and then write the data from the Tk app into the Word document?


Replies are listed 'Best First'.
Re^4: Automating Word with Perl
by merrymonk (Hermit) on Oct 29, 2008 at 11:45 UTC
    OK I think I can see what you are getting at and I can see that it would work well becase it is standard documenets
    that I am trying to create.
    The problem I am still having is to understand how to move to the position where I want to add the text.
    I looked at the description again for some sort of 'positioning' facilitiy.
    I found MoveToEnd which takes me to the end of the document.
    I also saw some references to the cursor position but not how to 'set it'.
    There is the the comment "The documents are constructed in a linear fashion, i.e. you add text to the
    document and generally don't move around the document a lot".
    This made me wonder if I am trying to do something that this application was not designed for.
    Some more guidance will be more than apprecaited.
      Win32::Word::Writer is a wrapper around Win32::OLE, using the ActiveX Word API.

      For the things that Word::Writer doesn't do out of the box, you need to do it "manually" using regular Win32::OLE Automation methods on the Word object model. The Word instance and the Word Document are both available.

      I recommend that you start by looking at Visual Basic (VBA) examples for how to do automate things in Word in general (Google it), then read the Win32::OLE docs to see how it's translated to Perl (it's different, but very similar). Then browse through the Word Document Object Model (here's how).

      As mentioned, "A good way to figure out how to do something is to record a Macro and then bring up the VBA window and inspect the code written by the Macro Recorder".

      Good luck!


Re^4: Automating Word with Perl
by merrymonk (Hermit) on Oct 29, 2008 at 16:30 UTC
    My copy of Perl is supplied my a 3rd person.
    Sadly it does not include word-write.
    I have downloaded the tar file and unzipped the contents.
    I did try simply storing the .pm files in ...win32/word but this failed (perhaps not surprisingly!).
    I have never been involved in adding anything like this to Perl.
    Can you summerise what I should do or point me at some instructions?
    I guess one question is can this be added or does it have to be part of a complete build of Perl?
      See A guide to installing modules for Win32

      (And in addition to the module, you obviously need Microsoft Word installed on the computer. An old version should do, since that's what I used when writing the module. Later versions of Word probably works too).


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://720141]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-07-24 12:41 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.