Good all the time of the day gentlemen

//подключаем PHPWord require_once 'PHPWord.php'; $PHPWord = new PHPWord(); //выбираем файл для работы $document = $PHPWord->loadTemplate('test.docx'); //изменим его $document->setValue('Value1', '123'); $document->save('test1.docx'); 

Eats-but I have prescribed $ {Value1} in the file. No mistakes. In the new file - there is no replacement. Who can about diagnose? (eats but PHPWord on hosting and examples from example work)

2 answers 2

There will be no errors if the class does not find a replacement template. Open the test.docx file with the archiver, look at the structure of the word / document.xml file, where the template is sewn up, there should be something like:

 <w:r> <w:t> ${Value1} </w:t> </w:r> 

If the pattern "$ {Value1}" symbol per symbol does not match, no replacement will take place.

  • Thanks, helped - sergey
  • @mixalef, and what was inserted instead of "$ {Value1}"? - LTKH

DocXGen Try this solution. Free and solves the problem when the Value was not written the first time. For example, if you first enter {} in the Word and then enter Value1 in these braces, the value will not be replaced, because the XML structure will be something like this:

 <w:r> <w:t> { </w:t> </w:r> <w:r> <w:t> Value1 </w:t> </w:r> <w:r> <w:t> } </w:t> </w:r>