in reply to Win32::OLE and Word: accessing all headers and comments
Loop through the collection of objects with 'in'
#!perl use strict; use Win32::OLE('in'); use Win32::OLE::Const "Microsoft Word"; Win32::OLE->Option(Warn => 3); my $Word = Win32::OLE->new('Word.Application'); $Word->{Visible} = 1; my $Doc = $Word->{Documents}->Open('c:/temp/HelloWorld.docx'); for my $Section (in $Doc->Sections){ printf "Section %d\n",$Section->{Index}; for my $Header (in $Section->Headers()){ printf "Header %d - %s\n",$Header->{Index}, $Header->Range->{Text}; } for my $Footer (in $Section->Footers()){ printf "Footer %d - %s\n",$Footer->{Index}, $Footer->Range->{Text}; } } for my $Comment (in $Doc->Comments){ printf "Comment %d - %s\n",$Comment->{Index},$Comment->Range->Text } undef $Doc; undef $Word;
It gets complicated if your header/footers include text inside shapes !
poj
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Win32::OLE and Word: accessing all headers and comments
by roho (Bishop) on Mar 19, 2019 at 11:00 UTC |