开发者

Find and replace a word in DOC document Perl

开发者 https://www.devze.com 2023-03-27 17:39 出处:网络
I have bunch of Microsoft Word开发者_高级运维 documents, and want to find and replace a word, e.g.

I have bunch of Microsoft Word开发者_高级运维 documents, and want to find and replace a word, e.g.

find the word banana replace it with apple


You could use Win32::OLE.

It seems that your interaction would look about like this (completely untested):

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();

Read the Win32::OLE documentation in conjunction with the VB documents for better/further information.

You might also find the tool "Multireplace" at the bottom of this page interesting.

0

精彩评论

暂无评论...
验证码 换一张
取 消