Forum


Replies: 5   Views: 3345
Add a table to a variable
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 peter  · 02-04-2013 - 18:53

Hi

I would like to add a table to a template variable; is that possible and how?

I've a template with several variables in it,one should be replaced with atable that is created for each time;

I've done this:

first i've an array of arrays; $arrays
then I create an instance of an table
$table = CreateTable::getInstance();
after that I createTable with my data
$table -> createTable($arrays, array('border' => 'none',));

them I utf8_encode all my variables including the table, if I skip that I get error

and then I add the table to the variable (and all other ariables)
$doc -> addTemplateVariable("variable",$table)


The table is only added as a string of the xml code and not interpreted as a table ('<w:tbl><w:tblPr><w:tblStyle w:val="TableGridPHPDOCX"><..........')

version is Pro 3.2, and I thinnk I had this working on 2.x but now when I tried it the variable wasreplaced with emptiness.





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

Hello,

You can do that using replaceTemplateVariableByHTML method. You just need to write the HTML table and set the placeholder.

Regards.

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

Hi

I probably missed to write this; the variable I'm trying to replace is itself within a table.

When using the suggested method nothing happends more than that the variable dissapears from the document.
When replacing avariablenot within another table it works.

Is thah how the function should work or is it a bug?

/Peter

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

Hello,

Please contact us (http://www.phpdocx.com/contact) to test your script.

Regards.

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

it was a bug but on my end.

thanks for the help