search

Home  >  Q&A  >  body text

Problems encountered when using opentbs to generate odt files: values ​​of the same key are displayed in the same row instead of separate columns.

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:

<?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 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 shows thin

| 156 | 233 | 110 |

The second line only displays heavy

| 128 | 25 | 412 |

The third line only displays total

| 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 used cell instead of row

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         |
+---------------------------------------+

P粉257342166P粉257342166259 days ago859

reply all(1)I'll reply

  • P粉116654495

    P粉1166544952024-04-07 16:11:53

    Regarding the parallel functionality , the results you are getting are correct. Parallel Features Perform a column-wise merge instead of a row-wise merge.

    For row-by-row merging, your template might look like this:

    +---------------------------------------------------------------+
    | Row number | Thin                     |  Heavy    |  Total    |
    +---------------------------------------------------------------+
    | [b.#]      | [b.thin;block=tbs:row]   | [b.heavy] | [b.total] |
    +---------------------------------------------------------------+

    For merging by column, your template might look like this:

    +-- -----------------------+
    |  Row number [b.#]        |
    +--------------------------+
    | [b.thin;                 |
    | block=tbs:cell;          |
    | parallel=tbs:table]      |
    +--------------------------+
    | [b.heavy]                |
    +--------------------------+
    |  [b.total]               |
    +--------------------------+

    reply
    0
  • Cancelreply