2014-10-27 323 views
1

在Word 2013中,使用搜索和替換(啓用或未啓用通配符),我想在Bye的段落開頭處替換每個出現的Hello在Word 2013中,匹配文檔開頭的通配符

的搜索模式:

^pHello

僅適用於非第一線,並在文檔的第一個段落的開頭不匹配Hello

如何在文檔開頭匹配Hello?在Perl中,這將作爲s/^Hello/Bye/完成。

回答

1

匹配文檔開頭的通配符似乎不存在。

我所做的是在文檔開始處添加段落標記,執行我的搜索,然後刪除段落標記。下面是它在Perl中的外觀:

my $word = Win32::OLE->new ('Word.Application', 'Quit') or die $!; 

$word->Selection->HomeKey ({Unit => wdStory}); # to the beginning of the doc 
$word->Selection->TypeText ({Text => "\n"}); # add the ^p 
$word->Selection->HomeKey ({Unit => wdStory}); # to the beginning of the doc 

my $search = $document->Content->Find; 

$search->{Text}    = "^pHello"; 
$search->Replacement->{Text} = "^pBye"; 
$search->Execute(); 

$word->Selection->Delete; # delete the ^p