How to add list to the loaded template in phpword
Asked Answered
D

1

9

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?

Dariodariole answered 1/6, 2017 at 8:7 Comment(5)
Define "not working".Contentious
if i do not add $section to $temp->setValue , it will workFermata
If I add $section to $temp->setValue, it will show empty page.(Headers do not work)Fermata
Solution here: #14560642Contentious
what is your expected value in $section with this line $temp->setValue('Value1', $section);Arad
M
1

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.

Minor answered 14/6, 2017 at 19:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.