Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Automating Word with Perl

by polypompholyx (Chaplain)
on Oct 25, 2008 at 15:47 UTC ( #719517=note: print w/ replies, xml ) Need Help??


in reply to Automating Word with Perl

Win32::OLE allows you to communicate directly with Word.

use Win32::OLE; use Win32::OLE::Const "Microsoft Word 12.0 Object Library"; use Win32::OLE::Const "Microsoft Office 12.0 Object Library"; my $word = Win32::OLE->new( 'Word.Application', 'Quit' ) or die "Can't create Word OLE: " . Win32::OLE->LastError . "\n"; $word->{'Visible'} = 1; my $doc = $word->Documents->Add or die "Can't create new Word document: " . Win32::OLE->LastError +. "\n"; my $selection = $word->Selection; # select current position $selection->{'Style'} = 'Title'; $selection->TypeText( 'Document title' ); $selection->TypeParagraph; $selection->{'Style'} = 'Normal'; $selection->TypeText( 'Lorum ipsum' ); $selection->TypeParagraph; $doc->SaveAs( 'foo.docx' ); $word->Quit;

The Visual Basic for Applications examples you'll be able to find in the MSDN library for Office can mostly be simply converted to Win32::OLE Perl code by changing . to -> and a := b to { a => b }.


Comment on Re: Automating Word with Perl
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-12-20 16:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls