Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add list to the loaded template in phpword

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?

like image 217
yiideveloper Avatar asked Jun 01 '17 08:06

yiideveloper


1 Answers

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.

like image 174
lax1089 Avatar answered Nov 02 '22 16:11

lax1089