Problem w/ Template.docx

May 4, 2013 at 7:18 AM
Hi every body,

The issue from the template is empty !
What's wrong with may code ?

My code :
<?php
// Include the PHPWord.php, all other classes were loaded by an autoloader
require_once 'PHPWord.php';
require_once 'PHPWord/Template.php';

$PHPWord = new PHPWord();
$template = $PHPWord->loadTemplate('Examples/Template.docx');

$template->setValue('Value1', '101');
$template->setValue('Value2', '102');
$template->setValue('Value3', '103');
$template->setValue('Value4', '104');
$template->setValue('Value5', '105');
$template->setValue('Value6', '106');
$template->setValue('Value7', '107');
$template->setValue('Value8', '1008');
$template->setValue('Value9', '1000');
$template->setValue('Value10', '10067');

$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('../ComperioV1/dossierPerso/Template.docx');
?>
Why that ?

Many thks for your advises !
May 14, 2013 at 6:38 AM
Edited May 14, 2013 at 6:38 AM
create template file "Template.docx" under the same directory of Template.php then edit the template file using microsoft word. you may put variable ${Value1}, ${Value2} .... to replace the value of setValue.
May 14, 2013 at 7:11 AM
replace :

$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('../ComperioV1/dossierPerso/Template.docx');

by :

$template->save('../ComperioV1/dossierPerso/Template.docx');
May 15, 2013 at 6:58 AM
Edited May 16, 2013 at 8:14 PM
Thank U guys for good advises.

Now i would like to know if i can have several templates and can i manage this ?

I issued, with MS Word, 3 templates (Templates1.docx, Templates2.docx, Templates2.docx) located in my site root folder. Any things worked out ...

Many thanks