1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| my $input_file = 'test.doc';
$input_file = Win32::GetCwd() . "/$input_file" if $input_file !~ /^(\w:)?[\/\\]/;
die "File $input_file does not exist" unless -f $input_file;
my $word = Win32::OLE->new('Word.Application', 'Quit') || die "Couldn't run Word";
my $doc = $word->Documents->Open($input_file);
my $index = 0;
# Extract using first method
for my $paragraph (in $doc->Paragraphs)
{
$index++;
# Remove trailing ^M (the paragraph marker) from Range.
my($text) = substr($paragraph->Range->Text, 0, -1);
print "Paragraph: $index. Text: <$text>\n\n";
}
print '-' x 50, "\n";
# Extract using second method
my $paraCount = $doc->Paragraphs->Count;
for ($index = 1 ; $index <= $doc->Paragraphs->Count ; ++$index)
{
my($text) = $doc->Paragraphs($index);
print "Paragraph: $index. Text: <", $text->Range->Text, ">\n\n";
}
print '=' x 50, "\n";
$doc->{Saved} = 1;
$doc->Close; |
Partager