Get a blank word document


$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate('./documents/invoice1.docx');
$section = $PHPWord->createSection();
$section->addText( $invname);
$section->addText( $organization_link_record['organization_link_address_1'] );
$section->addText( $organization_link_record['organization_link_address_2'] );
if (!empty( $organization_link_record['organization_link_address_3']))
{$section->addText( $organization_link_record['organization_link_address_3'] );}
if (!empty( $organization_link_record['organization_link_address_4']))
{$section->addText( $organization_link_record['organization_link_address_4'] );}

what am i doing wrong?


amok211 wrote Feb 12, 2015 at 10:51 AM

Same here.

I had been struggling with OpenTBS, and managed to generate .odt docs, although not achieveing exactaly what I wanted. So I've changed to PHPWord, but all I got is a blank screen. Besides, PHP debugging is kind of hell, so I don't truly know what's wrong with my code. As far as I know, if you are using a template, you won't need to add sections. My code looks like this:

      //Retrieve posted data
      $title = $_POST['title'];
      $msg = $_POST['msg'];  
      $name = $_POST['name'];
      $format = $_POST['format'];

      //check if retrieved data is ok
      echo ("<p> title: " + $title + "</p>");
      echo ("<p> msg: " + $msg + "</p>");
      echo ("<p> name: " + $name + "</p>");  

      //Include PHPWord
      $require = require_once '../librerias/PHPWord/PHPWord.php';

      //Instance PHPWord object
      $PHPWord = new PHPWord();

      //Load Template (same directory as this .php file)
      $document = $PHPWord->loadTemplate('test.docx');

      //Replace template fields 
      $document->setValue('title', $title);
      $document->setValue('msg', $msg);
      $document->setValue('name', $name);
      $document->setValue('weekday', date('l'));