Categories > OpenTBS with DOCX >

Dynamic table in DOCX

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Roger
Date: 2015-08-20
Time: 12:37

Dynamic table in DOCX

Sorry to ask for elementary help, but I'm struggling with my first serious use of OpenTBS. I need to tabulate some dynamic data in DOCX format, with the table like:

                        1-Mar-16    3-Apr-16    4-Jun-16
Sydney      Apple       Fred        Joe         Bill
Melbourne   Banana      Mary        Sue         Frank
Adelaide    Orange      Kylie       Alan        John

where all the data comes from one or more PHP arrays (which I can structure as necessary). The number of date columns (3 shown here) varies from 1 to 5, but is constant in any one dataset.

Can I do this with a single template (or should I select separate templates for 1-date-col, 2-date-col datasets etc)? If so, can you please suggest an efficient way to structure and key the data in PHP, and fields for the docx template? Thanks!
By: Roger
Date: 2015-08-21
Time: 07:38

Re: Dynamic table in DOCX

I've made significant progress myself, after putting in the necessary time to read the manual :)  In case it helps someone else, I structured the data like:
$dates = array('1-Mar-16','3-Apr-16','4-Jun-16');
$roster = array(
      array('place'=>'Sydney','fruit'=>'Apple','staff'=>array('Fred','Joe','Bill')),
      array('place'=>'Melbourne','fruit'=>'Banana','staff'=>array('Mary','Sue','Frank')),
      array('place'=>'Adelaide','fruit'=>'Orange','staff'=>array('Kylie','Alan','John')));
and used a template like this:
                                                                [d.val;block=tbs:cell;parallel=tbs:table]
[r.place;block=tbs:row;sub1=staff]   [r.fruit;block=tbs:cell]   [r_sub1.val;block=tbs:cell]
and PHP:
$TBS->MergeBlock('d', $dates);
$TBS->MergeBlock('r', $roster);
Works beautifully. The only detail that caught me for a while was that sub-blocks need to be nested, so the block in the first column has to be tbs.row, not tbs.cell. Thanks for the product!!
By: Skrol29
Date: 2015-08-26
Time: 17:17

Re: Dynamic table in DOCX

OK,so your problem seems solved.
Thank for sharing that.