I used PHPword to create a word document in my web application but I coud not implement list. I used the following code:
$PHPWord = new PHPWord();
$temp = $PHPWord->loadTemplate('temp.docx');
$section = $PHPWord->createSection();
$section->addListItem('List Item 1', 0);
$section->addTextBreak(1);
$temp->setValue('Value1', $section);
$temp->save('list.docx');
This code is not working. I managed to create a list in a new document but I could not add the list to the template (I could not assign a list to the specific value). How can I add the list?
As mentioned in above comment, a previous answer addressed your question.
Basically, you cannot provide a section
object as the second parameter of the setValue
method as it expects a string value for this parameter.
You may want to add the function described in the above previous answer to the Template.php file in the PHPWord directory to accomplish the functionality you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With