in reply to Style problem with Word/OLE
use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; use Cwd 'abs_path'; my $book = shift; if ( !$book ) { die "usage: $0 <word file>"; } $book = abs_path( $book ); my $word = Win32::OLE->GetActiveObject('Word.Application') || Win32::O +LE->new('Word.Application'); $word->{'Visible'} = 0; $word->{DisplayAlerts} = 1; my $file = $word->Documents->Open( $book ); if ( !$file ) { die "cannot open $book"; } my $paragraphs = $file->Paragraphs(); my $n = $paragraphs->Count(); for my $p (1..$n) { my $paragraph = $paragraphs->Item( $p ); print "paragraph $p\n"; print "before: $paragraph->{Style}->{NameLocal}\n"; my $text = $paragraph->{Range}->{Text}; $paragraph->{Range}->{Text} = $text; print "after: $paragraph->{Style}->{NameLocal}\n\n"; } $file->Close();
Output: paragraph 1 before: Heading 1 after: Heading 2 paragraph 2 before: Heading 2 after: Heading 3 paragraph 3 before: Heading 3 after: Normal paragraph 4 before: Normal after: Normal
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Style problem with Word/OLE
by ww (Archbishop) on Jul 06, 2013 at 20:08 UTC | |
by IlanB (Initiate) on Jul 06, 2013 at 20:57 UTC | |
|
Re^2: Style problem with Word/OLE
by poj (Abbot) on Jul 07, 2013 at 20:10 UTC | |
by IlanB (Initiate) on Jul 08, 2013 at 07:58 UTC |