use strict; use warnings;
use Win32::OLE::Const 'Microsoft Word';
my $file = 'C:\Strawberry\Perl\bin\2test.docx';
my $Word = Win32::OLE->new('Word.Application', 'Quit');
$Word->{'Visible'} = 0;
my $doc = $Word->Documents->Open($file) or die "Error opening the document!\n";
my $paragraphs = $doc->Paragraphs() ;
my $enumerate = new Win32::OLE::Enum($paragraphs);
while ( defined (my $paragraph = $enumerate->Next()) ) {
my $words = Win32::OLE::Enum->new( $paragraph->{Range}->{Words} );
while ( defined ( my $word = $words->Next() ) ) {
my $text = $word->{Text};
## print "$text \n";
if ($text =~ /[A-Z]{4}-[0-9]{1}/){
$paragraph->Select;
my $page_number = $Word->Selection->Information(wdActiveEndPageNumber);
print "Found $text in pg $page_number!\n";
}
}
}
$Word->ActiveDocument->Close ;
$Word->Quit;
####
Control HGRF-1(Negotiated), JFHH-1, ECIC-1, ECNK-1
ABDF-4
####
Control
HGRF
-
1
(
Negotiated
)
,
J
FHIH
-
1
... so on