Template SetValue not replacing in Word 2010

Dec 27, 2012 at 7:35 PM

I have recently found this product and have been able to successfully create new Word documents, but it seems I am unable to affect a template.  I am not sure if this is a Word version issue, but I am using Word 2010.

Following is the code I am using to replace two values:

 

<?php
require_once '../PHPWord/PHPWord.php';
$PHPWord = new PHPWord();
$reportname= $latisid.' - '.$devicename.'.docx';
$template= 'NewFixedAsset.docx';
$document = $PHPWord->loadTemplate($template);
$document->setValue('ValueOne', 'Test');
$document->setValue('ValueTwo', $proveng);
$document->save('./output/'.$reportname);
echo "<a href='http://10.1.11.246/prov_inv/output/".$reportname."'>Download New Fixed Asset Document";
?>

 

The text in Word is as follows:

DATE: ValueOne
PREPARED AND TAGGED BY:  ValueTwo

The template is loaded and the new document saved, though no replacements occur.

Am I missing something?  Is there a way to debug the setValue process?

Any guidance would be greatly appreciated!

Jun 13, 2013 at 9:19 AM
I have got the same type of problems.
And I cannot find any valid response in this forum.

It is very very unclear to me what exactly I need to create in Word in order to get the setValue populated.

is it a DOCVARIABLE, DOCPROPERTY, ${testValue}, ...
the documentation is far from complete i.e. an a to z explication is missing.

I hope that someone picks this up very soon. I cannot wait that much longer and am looking at alternative products that might fullfil our requirements if this does not get clarified.

P.
Jul 2, 2013 at 10:06 PM
Edited Jul 2, 2013 at 10:06 PM
patrickvdbemt wrote:
I hope that someone picks this up very soon. I cannot wait that much longer and am looking at alternative products that might fullfil our requirements if this does not get clarified.
I am in the same boat. There is no documentation anywhere saying how the word file should be set up. Is it a field or just text? Who knows. The documentation for PHPWord is very disappointing after using PHPExcel which was a great product.

I can load the template and create a new file with it but setValue() does absolutely nothing.

Very frustrating.
Dec 17, 2014 at 7:34 PM
Hi, I'm having the same problem. I've been trying to figure it out all day. The problem I've found is that if you type into the word document ${replace-me} it doesn't work. But If i type it in another text editor and paste it in, it works!

In theory anyway, I'm still having problems getting replacement to work inside the header and footer. Its difficult to tell if its the problem I've solved, or something different. :)