News

Creating and adding info to a template table in PHPdocx

  • Jun 06, 2011

If you have a template with a table, you can pass parameteres and info to it.
For the code, use a template like this:

Use this code:



require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$settings = array(
'header' => true
);

$docx->addTemplate('../files/TemplateTable.docx');

$docx->addTemplateVariable(
array(
array(
'NAME' => 'Product A',
'WEIGHT' => '10',
'PRICE' => '5',
),
array(
'NAME' => 'Product B',
'WEIGHT' => '20',
'PRICE' => '30',
),
array(
'NAME' => 'Product C',
'WEIGHT' => '25',
'PRICE' => '7',
),
),
'table',
$settings
);

$docx->addTemplateVariable('TOTALWEIGHT', '55');

$docx->addTemplateVariable('TOTALPRICE', '42');

$docx->addTemplateVariable('MYNAME', 'David Hume');

$docx->createDocx('template_table');