$variable
$value
$settings

require_once 'classes/CreateDocx.inc';
$docx = new CreateDocx();
$docx->addTemplate('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');
$docx->addTemplateVariable('NAME', 'David Hume');
$docx->createDocx('template_text.docx');

require_once 'classes/CreateDocx.inc';
$docx = new CreateDocx();
$docx->addTemplate('TemplateTable.docx');
$settings = array(
'header' => true
);
$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.docx');
5 Responses
Have just run this code:
require_once(’../library/phpdocx/classes/cCreateDocx.inc’);
$objDocx = new cCreateDocx();
$objDocx->fAddLink(’Link to Google’, ‘http://www.google.es’, ‘Arial’);
$objDocx->fCreateDocx(’example_link.docx’);
I have not received any errors to the screen, but no file can be found with the given name on my server.
Please help!
I’m trying to input a relatively long description (few paragraphs) into a variable. It corrupts the docx file because word can’t open it. Replacing variables works find when it’s just a few words. I’ve tried using the addText method to add it to the docx but that doesn’t seem to work either, perhaps because it’s a template?
When I use a template, I can not use functions such as addHTML (), AddTable (), addText ().
How could blend these two techniques. there is a chance to do the following:
$var = addHTML();
/ * then replace them * /
$docx -> addTemplateVariable (’VAR’, $ var);
thank you very much
Hello,
Please check included examples on phpdocx pro; you can use a method like this one:
$docx->addTemplateVariable(’NAME’,
‘David Hume
Character is the result of a system of stereotyped principles.‘,
‘html’);
Regards.
With php 5.2.8 zipArchive::open doesn’t work
Adding CREATE, OVERWRITE flags in CreateDocx.inc line 2452 will fix this:
if ($zipDocxTemplate->open($fileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)) {