how read MS Word summary properties?

G

Geoff Cox

Hello

Is it possible to use perl to read the summary properties of a Word
file?

I would like to get a total count of all the pages in about 500 Word
docs ...

Cheers

Geoff
 
H

Henry Law

Is it possible to use perl to read the summary properties of a Word
file?

I would like to get a total count of all the pages in about 500 Word
docs ...

Assuming you run under Win32, have you tried using Win32::OLE to
instantiate a document object and then use the relevant part of the
Microsoft Weird object model?

Henry Law <>< Manchester, England
 
G

Geoff Cox

Assuming you run under Win32, have you tried using Win32::OLE to
instantiate a document object and then use the relevant part of the
Microsoft Weird object model?

Henry,

have just clued into that and am having a go!

Thanks

Geoff
 
G

Geoff Cox

Assuming you run under Win32, have you tried using Win32::OLE to
instantiate a document object and then use the relevant part of the
Microsoft Weird object model?

Henry,

I have found some code which prints out a whole load of Word doc
properties, all of whcih seems correct, except for the number of pages
figure!?

Any idea why?

from a newsgroup message from Jan Dubois in 1998 ...

use strict;
use Win32::OLE qw(in);

my $Word = Win32::OLE->new('Word.Application', 'Quit');
my $Doc = $Word->Documents->Open('i:\tmp\test.doc');

foreach my $Property (in $Doc->BuiltinDocumentProperties) {
my $Name = $Property->Name;
local $Win32::OLE::Warn = 0;
my $Value = $Property->Value;

$Value = '***Error***' if Win32::OLE->LastError;
$Value = '<undef>' unless defined $Value;
printf "%s %s = %s\n", $Name, '.' x (40-length($Name)), $Value;
}
$Doc->{Saved} = 1;

Geoff
 
H

Henry Law

I have found some code which prints out a whole load of Word doc
properties, all of whcih seems correct, except for the number of pages
figure!?

Ah, well now you're about to discover that I know not the detail
whereof I speak ... just the principles. It's being a technical
architect and not a technical specialist that does it.

However, if you open up Word, and in the help look for "Microsoft Word
Visual Basic Reference" (you need to have VBA installed to find it),
then you'll find documentation of the complete Object Model that Weird
implements. I see that there is a "Document" object, which has as one
of its properties is the "Words" property, which according to the help
"Returns a Words collection that represents all the words in a range,
selection, or document ..."

That suggests that once you've zigged and zagged a bit in Win32::OLE
you should be able to do something like

$WordCount = $MyDoc->Words->Count;

Happy to help with your trial and error .. but it might be better to
take it to email from here on (hide our collective incompetence). The
reply-to address is valid.

Henry Law <>< Manchester, England
 
G

Geoff Cox

I only tried one doc file with this, but it worked perfectly on
my Win2000. Correctly indicated 2 pages in the doc file.

Mike

this is what Cindy Meister said ( on the MS Word newusers group,

"Aside from opening the document, no. Or, if you could force the
documents to repaginate or perform an explicit Word Count before
they're closed, then the correct number would probably be saved in the
property (assuming the document is opened on the same machine, with
the same printer driver and printer available)."

I tried lots of Word docs under Windows 98 and no accurate figures..

What version of which Perl are you using? I wondered whether the
latest perl/win32::eek:le comination might do better? I have Perl 5.8.0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top