Categories > OpenTBS with DOCX >

Problem in compilation of a table on docx

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: aroat
Date: 2014-01-17
Time: 10:04

Problem in compilation of a table on docx

(Sorry, I've previosly inserted the question  in the general section)

Hi everybody.
I'm trying to create a docx from a template.
I want to fill a table with the info coming form a php array of associative arrays.


$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS->NoErr = true;
$TBS->LoadTemplate('template.docx');
$cand=array("Nome" => "Alessandro","Cognome"=>"Roat");
$lingue=array();
$lingue[]=array("Lingua" => "Francese", "LivelloParlato"=>"buono", "LivelloScritto"=>"buono", "Certificazioni"=>"Nessuna");
$lingue[]=array("Lingua" => "Inglese", "LivelloParlato"=>"buono", "LivelloScritto"=>"buono", "Certificazioni"=>"Nessuna");
$TBS->MergeField('cand', $cand);
$TBS->MergeField('lingua', $lingue);
$TBS->Show(OPENTBS_DOWNLOAD, 'prova.docx');


in "template.docx file" I have a table like this (it is similare to the demo one).

--------------------------------------------------------------------------------------------------------------------------
|Lingua                                          |Livello Parlato       |Livello Scritto       |Certificazioni number   |
--------------------------------------------------------------------------------------------------------------------------
|[lingua.Lingua;block=tbs:row] |[lingua.LivelloParlato]  |[lingua.LivelloScritto] |[lingua.Certificazioni]            |
--------------------------------------------------------------------------------------------------------------------------

The template is correctly filled in the static fields (cand) however in the table I get only a blank table.


--------------------------------------------------------------------------------------------------------------------------
|Lingua                                          |Livello Parlato       |Livello Scritto       |Certificazioni number   |
--------------------------------------------------------------------------------------------------------------------------
|                                                    |                                |                               |                                |
--------------------------------------------------------------------------------------------------------------------------



Only if I change the code, using only the first item of $lingue

$TBS->MergeField('lingua', $lingue[0]);

I get the table with only the first item


--------------------------------------------------------------------------------------------------------------------------
|Lingua                                          |Livello Parlato       |Livello Scritto       |Certificazioni number   |
--------------------------------------------------------------------------------------------------------------------------
|Francese                                       |buono                        |buono                      |Nessuna                     |
--------------------------------------------------------------------------------------------------------------------------




How can I have to proceed to get the full table as I excpect, that is


--------------------------------------------------------------------------------------------------------------------------
|Lingua                                          |Livello Parlato       |Livello Scritto       |Certificazioni number   |
--------------------------------------------------------------------------------------------------------------------------
|Francese                                       |buono                        |buono                      |Nessuna                     |
--------------------------------------------------------------------------------------------------------------------------
|Inglese                                         |buono                        |buono                      |Nessuna                     |
--------------------------------------------------------------------------------------------------------------------------


Thanks
By: aroat
Date: 2014-01-17
Time: 12:35

Re: Problem in compilation of a table on docx

Solved, I need to use MegeBlock instead of MergeFields.

$TBS->MergeField('cand', $cand);
$TBS->MergeBlock('lingua', $lingue);

Thanks!
By: Skrol29
Date: 2014-01-18
Time: 01:11

Re: Problem in compilation of a table on docx

OK.