News

Insert an external Word document into your Word template

  • Jun 06, 2011

You may replace a single template variable within your Word template by the contents of a full docx document with just one single line of code and the help of the addTemplatevariable method:



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

$docx = new CreateDocx();

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

$docx->addTemplateVariable('WEIGHT1', '10');
$docx->addTemplateVariable('WEIGHT2', '20');
$docx->addTemplateVariable('WEIGHT3', '25');

$docx->addTemplateVariable('PRICE1', '5');
$docx->addTemplateVariable('PRICE2', '30');
$docx->addTemplateVariable('PRICE3', '7');

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

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

// Add the content of the document when $NAME$ variable is called.
$docx->addTemplateVariable('NAME', '../files/Text.docx', 'docx');

$docx->createDocx('template_docx_text');