Problems encountered when using opentbs to generate odt files: values of the same key are displayed in the same row instead of separate columns.
P粉257342166
P粉257342166 2024-04-06 20:18:18
0
1
435

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

P粉257342166
P粉257342166

reply all (1)
P粉116654495

Regarding the parallelfunctionality, the results you are getting are correct. ParallelFeaturesPerform 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] | +--------------------------+
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!