News

PHPDocX Templates and Charts

  • May 04, 2011

One of the coolest options of PHPDocX PRO is the use of templates. You cand add a placeholder variable to a docx document and replace it later with different type of elements, including chart.
For example, write $PIECHART$ somewhere in your Word document and the following code will replace it by a 3D pie chart:


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

$docx = new CreateDocx();

// This is the template you created with the $PIECHART$ variable
$docx->addTemplate('../files/TemplateChart.docx');

// The chart
$legends = array(
'legend1' => array(10, 11, 12),
'legend2' => array(30, 21, 12),
'legend3' => array(40, 41, 42)
);

$paramsChart =
array(
'data' => $legends,
'type' => 'pie3DChart',
'title' => 'Title',
'cornerX' => 20,
'cornerY' => 20,
'cornerP' => 30,
'color' => 2,
'textWrap' => 0,
'sizeX' => 10,
'sizeY' => 10,
'jc' => 'right',
'showPercent' => 1,
'font' => 'Times New Roman'
);

// Adding the chart to the document
$docx->addTemplateChart('PIECHART', $paramsChart);

$docx->createDocx('template_chart.docx');