SPUG: Win32::OLE help?

Tim Maher tim at consultix-inc.com
Fri Jun 17 17:13:03 PDT 2005

(This is a retitled and edited re-posting of a previous message.)

> Second, many people complain about the "primitive" Microsoft macro.
> This is weird claim given the richness of Office Automation. You can
> basically control every aspect of Word from virtually any other
> language.

That's an apples retort to an oranges gripe.

Macros are accessible even to the most Bozoid user (although IMHO
they can't be trusted to function properly). Win32::OLE, on the
other hand, is a big obstacle even to long-time programmers like
me, because when I read the documentation all I hear about are
wacky things like "apartment models", and I have no idea how to
do what I want with it.

For example, to italicize all the comments in my code samples, I
need to search for a "#" in style3 that's either at the beginning
of a line or at the start of a new word (but not in quotes), and
convert all the characters from the # to the end of the line to
italic. (Those comments were of course marked as italic when I
imported them into Word from HTML, but the italicization gets
lost somewhere along the way.)

> I've never written Office automation before in my life, yet I
> was able to open the online help, and in 5 minutes came up with quick (6
> lines) Perl scripts that demonstrate how Office can be automated using a
> Perl script. 

I'd very much like to learn how to use this technology from Perl, if
it can really help me. Is there a decent tutorial somewhere?
> 	use Win32::OLE;
> 	my $app = Win32::OLE->new('Word.Application');
> 	$app->{Visible} = 1;
> 	$app->Documents->Add( );
> 	my $sel = $app->Selection;
> 	$sel->TypeText( 'Hello Word' );

This example seems to just be assembling a Word doc. I need to
know what facilities there are for /manipulating existing docs/.
> And Office 2003 has excellent, extensively document, XML support.
> u.

Really? I bought it on the understanding that Word docs would be
/saved/ in XML, so that I could easily massage the raw data. But
the storage format is still some inscrutable proprietary format,
AFAIK. If XML is really in there somewhere, how do you get at it?

| Tim Maher, PhD     (206) 781-UNIX      (866) DOC-PERL     (866) DOC-UNIX |
| tim(AT)Consultix-Inc.Com  http://TeachMePerl.Com  http://TeachMeUnix.Com |
|   Watch for my Summer, 2005 book: "Minimal Perl for UNIX/Linux People"   |
|  See http://manning.com/Maher for details, and email notification signup |

More information about the spug-list mailing list