Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 }.

In reply to Re: Automating Word with Perl by polypompholyx
in thread Automating Word with Perl by merrymonk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2023-12-01 16:29 GMT
Find Nodes?
    Voting Booth?

    No recent polls found