I am using a library called OpenTbs to create odt using PHP, I am using it because of the dynamic generation of columns and rows.
I know how to create rows and columns, but I don't know how to organize them.
Let me add an example:
So first I will add this to my odt,
+-- ---------------------------------------------------+ | Thin | Heavy | Total | +------------------------------------------------------+ | [b.date] | | | +------------------------------------------------------+ | [b.thin; | | | | block=tbs:cell; | | | | parallel=tbs:table] | | | | | | | +------------------------------------------------------+ | [b.heavy] | | | +------------------------------------------------------+ | [b.total] | | | +------------------------------------------------------+
And then in the code I will use:
Plugin(TBS_INSTALL, OPENTBS_PLUGIN); $TBS->LoadTemplate('template.odt',OPENTBS_ALREADY_UTF8); $data = array( array('date' => '2013-10-13', 'thin' => 156, 'heavy' => 128, 'total' => 284), array('date' => '2013-10-14', 'thin' => 233, 'heavy' => 25, 'total' => 284), array('date' => '2013-10-15', 'thin' => 110, 'heavy' => 412, 'total' => 130), ); $TBS->MergeBlock('b', $data); // $TBS->Plugin(OPENTBS_DEBUG_INFO, true); $output_file_name ="test_download.odt"; $TBS->Show(OPENTBS_DOWNLOAD, $output_file_name); ?>
Output:
+ --------------------------------------+ | Thin | Heavy | Total | +---------------------------------------+ | 156 | 233 | 110 | +---------------------------------------+ | 128 | 25 | 412 | +---------------------------------------+ | 284 | 284 | 130 | +---------------------------------------+
All seams fine, but if we compare it to the array$data
$data = array( array('thin' => 156, 'heavy' => 128, 'total' => 284), array('thin' => 233, 'heavy' => 25, 'total' => 284), array('thin' => 110, 'heavy' => 412, 'total' => 130), );
You will see that the first line only showsthin
| 156 | 233 | 110 |
The second line only displaysheavy
| 128 | 25 | 412 |
The third line only displaystotal
| 284 | 284 | 130 |
In reality, content like this should be displayed:
+ --------------------------------------+ | Thin | Heavy | Total | +---------------------------------------+ | 156 | 128 | 284 | +---------------------------------------+ | 233 | 25 | 284 | +---------------------------------------+ | 110 | 412 | 130 | +---------------------------------------+
Then I realized that maybe adding them underneath each other was the problem. So don't use it on odt
+-- ----------------------------------------------+ | Thin | Heavy | Total | +-------------------------------------------------+ | [b.thin; | | | | block=tbs:cell; | | | | parallel=tbs:table] | | | +-------------------------------------------------+ | [b.heavy] | | | +-------------------------------------------------+ | [b.total] | | | +-------------------------------------------------+
I am using this
+-- -------------------------------------------+ | Thin | Heavy | Total | +----------------------------------------------+ | [b.thin; | [b.heavy] | [b.total] | | block=tbs:cell; | | | | parallel=tbs:table]| | | | | | | +----------------------------------------------+
Output:
+----------------------------------------------+ | | | | | | +----------------------------------------------+ | 128 | 25 | 412 | 522 | | +----------------------------------------------+
As you can see it doesn't iterate over the array well and produces blank columns and the data shown is random
So if anyone knows what's wrong with this please let me know
Thanks!
renew
I realized that in[r.thin;block=tbs:cell;parallel=tbs:table]
I usedcell
instead ofrow
So I tried changing it ->[r.thin;tbs:row;parallel=tbs:table]
,
It doesn't work, but the first iteration is correct:
+ --------------------------------------+ | Thin | Heavy | Total | +---------------------------------------+ | 156 | 128 | 284 | +---------------------------------------+
Regarding the parallel
functionality
, the results you are getting are correct. ParallelFeatures
Perform a column-wise merge instead of a row-wise merge.For row-by-row merging, your template might look like this:
For merging by column, your template might look like this: