Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Open a word(.doc) file and output the number of pages contained in it

by guha (Priest)
on Nov 26, 2003 at 14:49 UTC ( [id://310268]=note: print w/replies, xml ) Need Help??


in reply to Open a word(.doc) file and output the number of pages contained in it

If you're on Win and have Word installed you can use Win32::OLE as Corion indicated above.

Below is a working example

#!perl -w use strict; use Win32::OLE; use Win32::OLE::Const; use Win32::OLE::Variant; ## Start Word engine my $Word = Win32::OLE->new('Word.Application', 'Quit'); $Word->{'DisplayAlerts'} = 0; my $wdc = Win32::OLE::Const->Load("Microsoft Word"); my $tpl = "c:\\perltest\\pages.doc"; ## Subject to change ## Open template my $doc = $Word->Documents->Open($tpl, {ReadOnly => Variant(VT_BOOL, +1) } ) || die"add"; my $pages = $Word->ActiveDocument->BuiltInDocumentProperties( $wdc->{w +dPropertyPages} )->Value; $doc->Close( { SaveChanges => $wdc->{wdDoNotSaveChanges} } ); print " $tpl contains $pages pages\n";
HTH
  • Comment on Re: Open a word(.doc) file and output the number of pages contained in it
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 16:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found