Replies: 7   Views: 2310
Can't pass 'pstyle' from one wordfragment to another
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

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.