Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I would like to make changes to Word paragraphs using perl by reading the paragraph text, modifying it and writing it back. But even without changing anything, after writing back, the paragraph inherits the style of the subsequent paragraph. Below I demonstrate it with a file that contains 3 paragraphs with styles "Heading 1", "Heading 2" and "Heading 3". After writing back, the styles became "Heading 2" and "Heading 3" and "Normal". Any idea what am I doing wrong?
Thanks, Ilan
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"; } Output: paragraph 1 before: Heading 1 after: Heading 2 paragraph 2 before: Heading 2 after: Heading 3 paragraph 3 before: Heading 3 after: Normal
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Style problem with Word/OLE
by ww (Archbishop) on Jul 06, 2013 at 11:58 UTC | |
|
Re: Style problem with Word/OLE
by IlanB (Initiate) on Jul 06, 2013 at 17:45 UTC | |
by ww (Archbishop) on Jul 06, 2013 at 20:08 UTC | |
by IlanB (Initiate) on Jul 06, 2013 at 20:57 UTC | |
by poj (Abbot) on Jul 07, 2013 at 20:10 UTC | |
by IlanB (Initiate) on Jul 08, 2013 at 07:58 UTC |