jjap28 has asked for the wisdom of the Perl Monks concerning the following question:
I was able find/replace text in the body of the Doc file, thanks to internet, but I am not able to find/replace text in the header/footer.
$word = Win32::OLE-> GetActiveObject('Word.Application') || Win32::OLE-> new('Word.Application','Quit'); my $Wordsections = $word->{Sections}; my $sections = $doc->{Sections}; my $n_sections = $sections->{Count}; for my $s ( 1 .. $n_sections ) { my $section = $sections->Item($s); my $headers = $section->{Headers}; my $n_headers = $headers->{Count}; for my $h ( 1 .. $n_headers ) { my $header = $headers->Item($h); print $header->{Range}->{Text}, "\n"; #my $headerRange=$headers->Range("wdHeaderFooterIndex")->InRange +="TRUE"; $Wordsections->Find->ClearFormatting; $Wordsections->Find->{Text} = 'SECRET'; $Wordsections->Find->Replacement->{Text} = "NOFORN"; $Wordsections->Find->Execute({Replace => wdReplaceAll}); } my $footers = $section->{Footers}; my $n_footers = $footers->{Count}; for my $f ( 1 .. $n_footers ) { my $footer = $footers->Item($f); print $footer->{Range}->{Text}, "\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: find and replace text in header and footers of MS Office doc and excel
by pryrt (Abbot) on Oct 11, 2016 at 14:09 UTC | |
by jjap28 (Initiate) on Oct 11, 2016 at 14:30 UTC | |
by Anonymous Monk on Oct 11, 2016 at 15:17 UTC | |
by marto (Cardinal) on Oct 11, 2016 at 15:24 UTC | |
by Corion (Patriarch) on Oct 11, 2016 at 15:19 UTC | |
by Anonymous Monk on Oct 11, 2016 at 15:52 UTC | |
by jjap28 (Initiate) on Oct 27, 2016 at 17:37 UTC |