how read MS Word summary properties?

Discussion in 'Perl Misc' started by Geoff Cox, Dec 30, 2003.

  1. Geoff Cox

    Geoff Cox Guest

    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
    Geoff Cox, Dec 30, 2003
    #1
    1. Advertising

  2. Geoff Cox

    Henry Law Guest

    On Tue, 30 Dec 2003 22:12:27 GMT, Geoff Cox
    <> wrote:

    >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
    Henry Law, Dec 30, 2003
    #2
    1. Advertising

  3. Geoff Cox

    Geoff Cox Guest

    On Tue, 30 Dec 2003 22:52:50 +0000, Henry Law
    <> wrote:

    >On Tue, 30 Dec 2003 22:12:27 GMT, Geoff Cox
    ><> wrote:
    >
    >>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,

    have just clued into that and am having a go!

    Thanks

    Geoff




    >
    >Henry Law <>< Manchester, England
    Geoff Cox, Dec 31, 2003
    #3
  4. Geoff Cox

    Geoff Cox Guest

    On Tue, 30 Dec 2003 22:52:50 +0000, Henry Law
    <> wrote:


    >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





    >
    >Henry Law <>< Manchester, England
    Geoff Cox, Dec 31, 2003
    #4
  5. Geoff Cox

    Henry Law Guest

    On Wed, 31 Dec 2003 20:25:57 GMT, Geoff Cox
    <> wrote:

    >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
    Henry Law, Dec 31, 2003
    #5
  6. Geoff Cox

    Geoff Cox Guest

    On Fri, 02 Jan 2004 02:49:03 GMT, Mike Flannigan
    <> wrote:



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



    >
    >
    >Mike Flannigan
    >
    Geoff Cox, Jan 2, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    431
    Guest
    Nov 3, 2003
  2. Iain
    Replies:
    0
    Views:
    324
  3. Ruby Quiz

    [SUMMARY] Word Chains (#44)

    Ruby Quiz, Sep 1, 2005, in forum: Ruby
    Replies:
    12
    Views:
    198
    James Edward Gray II
    Sep 2, 2005
  4. Ruby Quiz

    [SUMMARY] Word Search (#107)

    Ruby Quiz, Jan 4, 2007, in forum: Ruby
    Replies:
    0
    Views:
    94
    Ruby Quiz
    Jan 4, 2007
  5. Ruby Quiz

    [SUMMARY] Word Blender (#108)

    Ruby Quiz, Jan 11, 2007, in forum: Ruby
    Replies:
    6
    Views:
    98
    Ben Bleything
    Jan 17, 2007
Loading...

Share This Page