Serial Letter

Oct 12, 2012 at 7:46 AM

Hello,

I want to use PHPWord to create a serial letter. I have a template for the letter, but how can I include it several times. But I dont want to have generated x single files, I want to append it all into one file. I think about something like this.

$sql = "SEELECT Name, street, plz, town .... From adresses";
$result = mysql_query($sql);

$PHPWord = new PHPWord();

while ($person = mysql_fetch_array($result))
{
  $document = $PHPWord->loadTemplate('Template.docx');

  $document->setValue('Value1', $person['Name']);
  $document->setValue('Value2', $person['street']);
  $document->setValue('Value3', $person['plz']);
  $document->setValue('Value4', $person['town']);
  $document->setValue('Value5', $person['country']);
}


$document->save('SerialLetter1.docx');

Is it possible with PHPWord?
It would also be possible to generate singele files, if it is possible
to connect them afterwards to one WORD-file.
Thanks for answering.

Thami