Ray Smith has asked for the wisdom of the Perl Monks concerning the following question:
I have used Win32::OLE to do some parsing of MS Word files. I've been unsuccessful in my attempt to the paragraph numbers from the source file.
The following is a likely example in Visual Basic, but I've not been able to successfully translate it into Perl.
If Selection.Paragraphs(1).Range.ListParagraphs.Count = 1 Then MsgBox Selection.Paragraphs(1).Range.ListFormat.ListLevelNumber Else MsgBox "Not a numbered paragraph" End If
The following is a snipit of my working OLE MS Word access:
sub doc2pt { my ( $docfile, $docpt, # Converted text file ) = @_; require Win32::OLE; require Win32::OLE::Enum; # NOTE: Win32::OLE appears to need + abs path my $document = Win32::OLE -> GetObject(abs_path($docfile)); die "Can't GetObject($docfile) $!\n" if !defined($document); print "Extracting Text ...\n"; open DOCPT, ">$docpt" or die "Can't open docpt file $docpt: $!"; my $paragraphs = $document->Paragraphs(); my $enumerate = new Win32::OLE::Enum($paragraphs); while (defined($paragraph = $enumerate->Next())) { my $style = $paragraph->{Style}->{NameLocal}; print DOCPT "style==>$style\n"; ### my $range = $paragraph->{Range}; ### my $count = $range->ListParagraph(); ### if (defined($count)) { ### my $paranum = $range->ListFormatListLevelNumber(); ### print DOCPT "paranum==>$paranum\n"; ### } my $text = $paragraph->{Range}->{Text}; $text =~ s/[\n\r]//g; $text =~ s/\x0b/\n/g; print DOCPT "text==>$text\n"; } close DOCPT; }
I would greatly appreciate any suggestions on how to solve this problem.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using OLE to find MS Word paragraph numbers
by Util (Priest) on Oct 20, 2011 at 14:13 UTC |