my $word = Win32::OLE->GetActiveObject('Word.Application')
|| Win32::OLE->new('Word.Application','Quit')
or die Win32::OLE->LastError();
####
my $doc = $word->Documents->Open('C:\\Perl\\home\\001f.doc');
##
##
my $doc = $word->Documents->Open( { FileName => 'C:\\Perl\\home\\001f.doc', ReadOnly =>1 }) or die Win32::OLE->LastError();
SaveAs({FileName => 'exampletext.doc', FileFormat => wdFormatDocument,})
$doc->Close( { SaveChanges => $wdc->{wdDoNotSaveChanges} } );
##
##
Class Selection
Member of Word
------------------------------------
Property Words As Words
read-only
Member of Word.Selection
Property Characters As Characters
read-only
Member of Word.Selection
==========================
Sub ShrinkDiscontiguousSelection()
Member of Word.Selection
------------------------------------
Property Words As Words
read-only
Member of Word.Selection
Property Characters As Characters
read-only
Member of Word.Selection
##
##
#!/usr/bin/perl
use Cwd 'abs_path';
use warnings;
use strict;
use Win32::OLE 'CP_UTF8';
$Win32::OLE::CP = CP_UTF8;
binmode STDOUT, 'encoding(utf8)';
print abs_path($0) . "\n";
print "=========\n";
my $document_name = 'C:\\Perl\\home\\thisIsPerl.doc';
my $word = Win32::OLE->GetActiveObject('Word.Application')
|| Win32::OLE->new('Word.Application')
or die Win32::OLE->LastError();
$word-> {visible} = 0;
$word->Application->Selection;
my $document = $word->Documents->Open( { FileName => $document_name, ReadOnly =>1 }) or die Win32::OLE->LastError();
my $paragraphs = $document->Paragraphs ();
my $n_paragraphs = $paragraphs->Count ();
print "Words:", $word->Selection->Words->{Count}, "\n";
print "Characters:", $word->Selection->Characters->{Count}, "\n";
print "Paragraphs: ", $word->Selection->Paragraphs->{Count}, "\n";
$document->Close();
$word->exit;
$word->Quit;
Administrator@cepido /cygdrive/c/Perl/home
$ ./internet04_pgcnt.pl
/cygdrive/c/Perl/home/internet04_pgcnt.pl
=========
Words:1
Characters:1
Paragraphs: 1
##
##
#!/usr/bin/perl -w
use strict;
use warnings;
use Win32::OLE::Const 'Microsoft Word';
my $file = 'C:\\Perl\\home\\thisIsPerl.doc';
my $Word = Win32::OLE->new('Word.Application', 'Quit');
$Word->{'Visible'} = 0;
my $doc = $Word->Documents->Open($file);
my $paragraphs = $doc->Paragraphs() ;
my $n_paragraphs = $paragraphs->Count ();
for my $p (1..$n_paragraphs) {
my $paragraph = $paragraphs->Item ($p);
my $words = Win32::OLE::Enum->new( $paragraph->{Range}->{Words} );
while ( defined ( my $word = $words->Next() ) ) {
my $font = $word->{Font};
print "IN_Text:", $word->{Text}, "\n" if $word->{Text} !~ /\r/;
#print $text;
#$font->{Bold} = 1 if $word->{Text} =~ /Perl/;
}
print "=============\n";
}
$Word->ActiveDocument->Close ;
$Word->exit;
$Word->Quit;