I'am using a library called OpenTbs to create an odt with PHP, I use it because dynamically generates columns and rows.
I know how to create the rows and the columns, what I don't know is how to organize them.
let me add an example:
So first I will add this on 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:
<?php
include_once('tbs_class.php');
include_once('plugins/tbs_plugin_opentbs.php');
$TBS = new clsTinyButStrong;
$TBS->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 alright, however if we compare this with 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 in the first row it shows only thin
| 156 | 233 | 110 |
In the second row only shows heavy
| 128 | 25 | 412 |
and in the third row only shows total
| 284 | 284 | 130 |
When in reality should show something like this:
+ --------------------------------------+
| Thin | Heavy | Total |
+---------------------------------------+
| 156 | 128 | 284 |
+---------------------------------------+
| 233 | 25 | 284 |
+---------------------------------------+
| 110 | 412 | 130 |
+---------------------------------------+
then i realized, that maybe adding them below each other was the problem. so instead of using this on the 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 generates blank columns, furthermore the data displayed is random
So if anyone knows what is wrong with this, please let me know
Thanks!
UPDATE
I realized that in [r.thin;block=tbs:cell;parallel=tbs:table]
I use cell
instead of row
So I tried to change it -> [r.thin;tbs:row;parallel=tbs:table]
,
It didn't work, However the first iteration is correct:
+ --------------------------------------+
| Thin | Heavy | Total |
+---------------------------------------+
| 156 | 128 | 284 |
+---------------------------------------+
The result you have is correct regarding to the parallel feature
.
The parallel feature
performs a kind of merge by columns instead of merge by rows.
For a merge by rows, your template could be like this :
+---------------------------------------------------------------+
| Row number | Thin | Heavy | Total |
+---------------------------------------------------------------+
| [b.#] | [b.thin;block=tbs:row] | [b.heavy] | [b.total] |
+---------------------------------------------------------------+
For a merge by columns, your template could be like this :
+-- -----------------------+
| Row number [b.#] |
+--------------------------+
| [b.thin; |
| block=tbs:cell; |
| parallel=tbs:table] |
+--------------------------+
| [b.heavy] |
+--------------------------+
| [b.total] |
+--------------------------+