我想逐个字符地选择一个单词,除非遇到空格。我收到一个错误,因为“如果没有包或对象引用,就无法调用方法“MoveRight””。请帮我。提前致谢。下面是我的代码:
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE qw(in);
use Win32::OLE::Const 'Microsoft Word';
my $selection;
my $word = new Win32::OLE 'Word.Application','' or die "Cannot start
word!\n";
$word->{visible}=0;
my $doc = $word->Documents->Open( 'C:\\PerlScripts\\myTest.docx' );
$selection = $word->Selection;
$selection->Find->{Text} = "hi";
$selection->Find->{Forward} = 'true';
$selection->Find->{MatchWildcards} = 'true';
$selection->Find->{MatchPrefix} = 'true';
if ( $selection->Find->Execute ) {
print "The search text was found\n";
while($selection->Next ne " ")
{
$selection = $selection->MoveRight({Unit => wdCharacter, Count => 1, Extend => wdExtend}) ;
}
print $selection->{Text};
} else {
print "The search text was not found\n";
}