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  · 03-09-2019 - 11:24

Hello supportteam,

unfortunately my problem was not solved. I've tryed a lot but without success.

I need to create (more than one) wordfragments and place all into a parent wordfragment, which belongs to a document. Each of these sub-wordfragments should be a own paragraph on which I can use paragraph-styles.

Here is a sample-code which will illustrate my problem:

$docx = new CreateDocxFromTemplate(TEMPLATEPATH . 'Test1.docx');


$text1 = new WordFragment($docx);                                       
$text1->addText('Text one');
$text2 = new WordFragment($docx);                                       
$text2->addText('Text two');
$text3 = new WordFragment($docx);                                       
$text3->addText('Text three');


$text4_1 = new WordFragment($docx);
$text4_1->addText('Text 4_1, ');
$text4_2 = new WordFragment($docx);
$text4_2->addText(
                                        array(
                                                array(
                                                       'text'  =>   'Text 4_2 ',
                                                       'b'     =>   'on'
                                                )
                                        )
                                );

$text4_collect[1] = $text4_1;
$text4_collOpt[1] = array(      'pStyle' =>   'H2Interessenvertretung');
$text4_collect[2] = $text4_2;
$text4_collOpt[2] = array(      'pStyle' =>   'H2Selbstbestimmung');

$text4 = new WordFragment($docx);                                       
$text4->addText(array($text4_collect[1]), $text4_collOpt[1]);
$text4->addBreak(array('type' => 'line')); // how to get a hard line-break?
$text4->addText(array($text4_collect[2]), $text4_collOpt[2]);




$singleparts[1] = $text1;
$spOptions[1] = array('pStyle' => 'Titel2');
$singleparts[2] = $text2;
$spOptions[2] = array('pStyle' => 'Titel3');
$singleparts[3] = $text3;
$spOptions[3] = array(  'pStyle'        =>   'H2Selbstbestimmung',
                        'border'        =>   'single',
                        'borderWidth'   =>   '24',
                        'borderColor'   =>   'FF0000');
$singleparts[4] = $text4;


ksort($singleparts, SORT_NUMERIC);

$wf_top = new WordFragment($docx);
foreach($singleparts as $idx => $sp) {
        $wf_top->addText(array($sp), $spOptions[$idx]);
}

$docx->replaceVariableByWordFragment(array('content' => $wf_top), array('type' => 'block'));

$docx->createDocx('test_template');

text1 to text3 works fine as paragraphs but text4 should be a collection of wordfragments (each of them should be a paragraph which I can separatly format like a paragraph (borders and so on ...)).
Is there a way to do it?

Btw. is there a way to get a 'hard' line-break? Because addBreak(array('type' => 'line')); always makes a 'soft' line-break.

I am grateful for any help!!!

By the way, I've a premium license