This project is read-only.

How to create fields in Word for PHPWord template

May 28, 2013 at 8:54 AM
Edited May 28, 2013 at 9:24 AM
Hi

How do I create fields in Word in order to change the value of it in PHPWord? I tried to use Insert->Quickparts->Comments but that doesn't work. I use Word 2007.

This is my code to change the value:
$filename = 'joren.docx';
$PHPWord = new PHPWord();
$template = $PHPWord->loadTemplate('files/cv/test.docx');
$template->setValue('field1', 'Somebody someone');
$template->save('files/cv/'.$filename);

$downlink = 'files/cv/'.$filename;
header("Content-type: application/vnd.ms-word");
header("Content-disposition: attachment; filename=".$filename.";");
header('Content-Length: '.filesize($downlink));
header("Pragma: no-cache");
header("Expires: 0");
ob_clean();
@readfile($downlink);