Forum


Replies: 4   Views: 3136
Using template
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by alberto  · 30-12-2011 - 09:11

Hi,
i have a template ( t.docx ) that contains a table. I have also an array with n elements, I would create a page in a docx for each element in my array and each page must contains the table. I'm able to insert the template data in t.docx but when I create the document I obtain only page. Can someone write me an example code please?

Thanks

Alberto

Posted by admin  · 11-04-2013 - 12:13

If you wish to create n tables (where n is not yet define) the simplest solution is first generate a docx with n pages with n variable names (you may do that from a single variable replacing it n times and formatting it to have a page break after it) and later on do the substitution of the dynamically generated variables.

Posted by alberto  · 11-04-2013 - 12:13

I wouldn't use a template variable, i would add immediately a table and a page break...

Alberto

Posted by alberto  · 11-04-2013 - 12:13

i have a code like this:

foreach($elements as $e ) {

if (!is_null($e)) {

$valuesTable = array(
array(
"1",
"2",
),
array(
$e->1(),
$e->2()
),
array(
"3",
"4"
),
array(
$e->3(),
$e->4()
),
array(
"5",
"6"
),
array(
$e->5(),
$e->6()
)
);


$docx->addTemplate('templates/element/high.docx');
$docx->addTemplateVariable('1', $e->1());
$docx->addTemplateVariable('2', $e->2());


$docx->addBreak('page');
$i++;
}
}

Why i have only one table in one page? $elements has more elements.

Alberto