Replies: 7   Views: 261
Can't pass 'pstyle' from one wordfragment to another

Posted by admin  · 09-08-2019 - 16:06


If the first parameter of addText is an array:

$individualparts = array();
$individualparts[4] = $text1;

The method gets the inline contents of the WordFragments, so paragraph tags are removed (pStyle are applied to paragraph tags). If you set a pStyle in the second parameter, then it applies to the whole paragraph and character styles (like caps) are inherited to child contents. MS Word doesn't allow applying custom paragraph styles to run-of-text contents (only to paragraph tags), you need to use character styles to keep them when using an array and addText. You can use the rStyle option to apply a character style.

This sample uses character styles:

$text = array();
$text[] =
        'text' => 'Text MyStyle',
        'rStyle' => 'MyStyle1'
$text[] =
        'text' => ' text MyStyle2.',
        'rStyle' => 'MyStyle2'


You can use importStyles and createCharacterStyle to import and generate character styles.