Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Regarding the "Comment" object in Perl's Win32::OLE

by karthik4perl (Initiate)
on Jan 17, 2005 at 05:43 UTC ( [id://422677]=perlquestion: print w/replies, xml ) Need Help??

karthik4perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
 
   I am writing code for extracting the "Comments" from a "Word" document and displaying it. I am using Win32::OLE.

   Please help me with the portions where I am stuck:
   
   1) How can I extract the "PageNumber" from which the comment is placed in the "Word" document?
   2) How to copy all the comments from one "Word" document to another "Word" document using perl?   

Here's the code:

    use Win32::OLE qw/ in /;

    my $Word;
    my $Doc;
    my $file;
    my $file1 = "c:\some.doc";

    $Word = Win32::OLE->new('Word.Application', 'Quit');
    $Doc = $Word->Documents->Open($file1);
 
    foreach my $c (in $Doc->{Comments}) {
      my $tag = $c->{Initial} . $c->{Index};

      print b($c->{Scope}{Text}),"  ",$tag,"-",$c->{Range}
      {Text},br,br;
    }

Thanks
(karthik4perl)

  • Comment on Regarding the "Comment" object in Perl's Win32::OLE

Replies are listed 'Best First'.
Re: Regarding the "Comment" object in Perl's Win32::OLE
by rdfield (Priest) on Jan 17, 2005 at 10:20 UTC
    You'll probably find it helpful to use the following lines at the top of your code:
    use warnings; use strict;
    as you appear to be using a number of undeclared functions and your definition of $file1 is definitely incorrect - backslashes and double quotes don't do what you obviously expect.
    A good thing for you to do right now would probably have a read of perlman:perldebug have a look at the values in your variables. Another tip would be to check the return values of your external calls - are you sure that $Word is defined before you call methods on it?

    Update:I ran the code you supplied and it returns:

    Undefined subroutine &main::b called at 422677.pl line 14.
    So it looks like you haven't posted the exact code you're trying to run.

    rdfield

      I would guess that the functions "b" and "br" indicate that the line
      use CGI qw(:standard);
      is missing from the top of the OP's code. But that's just a guess.
        > But that's just a guess
        
        more like "blindingly obvious", I would think :) The trick is to get the OP to think through the problem - no-one learns from been spoon-fed answers.

        rdfield

Re: Regarding the "Comment" object in Perl's Win32::OLE
by jdporter (Paladin) on Jan 17, 2005 at 16:59 UTC
    Others have answered your specific question, but I'd like to make a comment on your code. You're doing things like
    $Doc->{Comments}
    $c->{Scope}{Text}
    and
    $c->{Range}{Text}
    While this may work, it's not good style, and isn't guaranteed to work as you expect. Better to call the accessor methods, rather than violate the data abstraction model; i.e.:
    $Doc->Comments
    $c->Scope->Text
    and
    $c->Range->Text
    You only need the curly braces when assigning to the like-named properties, e.g.
    $Word->{Visible} = 1;
Re: Regarding the "Comment" object in Perl's Win32::OLE
by Madams (Pilgrim) on Jan 19, 2005 at 01:47 UTC
    Just a note on your "item 1":

    "Page Numbers" per se, DO NOT EXIST in MSWord documents. They are auto computed EVERY time a document is opened and/or the default printer and/or any styles change.

    A document can have different pagination on different computers due to the above issues.

    See Word's Numbering Explained.

    Otherwise you just need to spend some time with:

    1. a VBA book,
    2. the Object Models of the various OLE enabled programs (see their help files/manuals), and
    3. the POD for Win32::OLE (to help translate VBA code to perl).

    Good luck %^)


    qq/madams55075.spamtrap.@comcast.net/=~s/\.spamtrap\.//;

Log In?
Username:
Password:

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

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

    No recent polls found