Forum


Replies: 2   Views: 3092
Addtext method not behaving as expected on wordfragment
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 AndrewCooper  · 14-06-2016 - 10:07

I have the following code.

$docx = new CreateDocx();

$item1 = new WordFragment($docx);
$item1->addText(array("text" => 'Chapter 1', "bold" => true));
$item2 = new WordFragment($docx);
$item2->addText('Section');
$item3 = new WordFragment($docx);
$item3->addText('Another TOC entry');

$item2->addBreak(array("type" => "line", "number" => 1));
$item2->addText("After the break.");

$itemList= array(
    "blah",
    array($item1),
    array($item2),
    array($item3)
);

$docx->addList($itemList);

If you notice, I used the addText option of an array in the 4th line above for $item1.  All the other items show up on the list just fine.  However $item1 just shows up as a blank line.  I looked in the documentation and there doesn't seem to be anything that indicates this shouldn't work.

Thanks,

Andrew 

Posted by admin  · 14-06-2016 - 11:00

Hello,

This syntax doesn't exist:

$item1->addText(array("text" => 'Chapter 1', "bold" => true));

For single strings you must use:

$item1->addText('Chapter 1', array("bold" => true));

Or for 'run of texts':

$item1->addText(array(array("text" => 'Chapter 1', "bold" => true)));

Regards.

Posted by AndrewCooper  · 14-06-2016 - 11:03

Ah...  so I have to put the array in an array.  Okay. Works perfectly.

Thanks!

Andrew