note
polypompholyx
<p>[cpan://Win32::OLE] allows you to communicate directly with Word.</p>
<code>
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;
</code>
<p>The Visual Basic for Applications examples you'll be able to find in the <a href="http://msdn.microsoft.com/en-us/library/bb726436.aspx">MSDN library for Office</a> can mostly be simply converted to <code>Win32::OLE</code> Perl code by changing <code>.</code> to <code>-></code> and <code>a := b</code> to <code>{ a => b }</code>.</p>
719497
719497