Forum


Replies: 7   Views: 2409
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 Siegfried  · 09-08-2019 - 13:43

Hello supportteam,
how can I pass the pStyle Option from one WordFragment to another?

here is a simplified sample of my code:

$docx = new CreateDocxFromTemplate($this->templateName);
$wfMain = new WordFragment($docx);
$wfMain->addText('Title:', array('pStyle' => 'Heading1'));
$wfMain->addText('SubTitle:', array('pStyle' => 'Heading2'));
$wfMain->addText('SubSubTitle:', array('pStyle' => 'Heading3'));


$individualparts = array();

$text1 = new WordFragment($docx);
$text1->addText('Hello world 1', array('pStyle' => 'Heading3', 'caps' => 'true'));
$text2 = new WordFragment($docx);
$text2->addText('Hello world 2', array('pStyle' => 'Heading1'));
// ... and more individual parts like charts (all should be WordFragments with individual styles from the word-template)

$individualparts[4] = $text1;
$individualparts[2] = $text2;
ksort($individualparts, SORT_NUMERIC); // sorting the individual parts


$wfMain->addText('$individualparts'); // here I lost the pStyle from $text1 and $text2
// $wfMain->addText('$individualparts', array('pStyle' => 'Heading2')); // this works but unfortunately for all $individualparts


$docx->replacevariableByWordfragment(array('placeholder' => $wfMain), array('type' => 'block'));
$docx->createDocx('Bericht');

I lost pStyle from $text1 and $text2 bu  interestingly the 'caps' - option works ... why not pStyle?
Any help for me please?

Best regards Siegfried