2011-08-13 62 views

回答

2

你可以使用Win32::OLE更換。

看來你的互動看起來大約像這樣(沒有經過充分測試):

use Win32::OLE; 

my $word = Win32::OLE->new('Word.Application') or die "Could not find Word.\n"; 

my $doc = $word->Documents->Open($filename); 
my $content = valof $doc->{Content}; 
$content =~ s/banana/apple/g; 
$doc->{Content} = $content; 
$doc->Save(); 
$doc->Close(); 
$word->Quit(); 

閱讀的Win32 :: OLE文檔連同更好/更多信息的VB文件。

您可能還會在this page的底部找到有趣的工具「Multireplace」。

+0

你不能在Range對象上使用正則表達式替換。 – Zaid

+0

@Zaid:謝謝你提供的信息。我現在編輯使用'valof',但我無法測試這個。也許你有更好的答案? – Svante

+0

在[相關問題]中有一個合理的例子(http://stackoverflow.com/questions/3774799/how-do-i-apply-formatting-to-a-particular-word-in-a-docx-file- using-win32ole-in)我已鏈接。 – Zaid