TinyButStrong - the PHP Template Engine
Categories > OpenTBS with ODS >

Generate multiple columns in ODT

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: Fabio Rocha
Date: 2012-07-10
Time: 04:59

Generate multiple columns in ODT

Hi, all.
I'm trying to generate multiple cells in one row. I can generate the result in many rows with tag table-row, but it is important to display the items in one row. In PHP side I have:
$users = array(
            array('name'=>'Fabio','sex'=>'m'),
            array('name'=>'Anirton','sex'=>'m'),
            array('name'=>'Karen','sex'=>'f'),
        );
$TBS->MergeBlock('blk_name', $users);
.
My template, inside a table cell, looks like:
[block_name.name;block=table:table-cell] - [blk_name.sex]
I tried different ways but still get just one column. Hope anyone can help. Thanks in advance.
By: Skrol29
Date: 2012-07-10
Time: 15:42

Re: Generate multiple columns

Hello Fabio,

Your snippet looks correct.
What do you exactly have as result?
By: Fabio Rocha
Date: 2012-07-10
Time: 21:12

Re: Generate multiple columns

I only get one column with the data of the first record. If I put more blank columns in the table, the data gets merged. I mean, if there is one column, only the first element of the array appears. If I put two columns, then the first and the seconde elements appear, and so on.
By: Skrol29
Date: 2012-07-11
Time: 21:32

Re: Generate multiple columns

Hi,

I cannot reproduce your behavior.
I've just notice that in your snippet there is a mistake. A block is badly named. You have to replace
[block_name.name;block=table:table-cell] - [blk_name.sex]
with
[blk_name.name;block=table:table-cell] - [blk_name.sex]

If the parameter "block" is not found for the merged block, then TBS merges only one record.
By: Fabio Rocha
Date: 2012-07-12
Time: 04:03

Re: Generate multiple columns

Actually, I just put that code as an example. My block name is 'assinaturas' and the code goes as followed:

// Pré-processamento das assinaturas.
$this->hasPeritos = array();
foreach ($this->laudoHasPeritos as $perito_indice => $laudoHasServidor)
{
    $this->hasPeritos[$perito_indice]['nome'] = $this->customUCWords($laudoHasServidor->servidor->nome);
    $this->hasPeritos[$perito_indice]['desGen'] = ($laudoHasServidor->servidor->serv_sex == 'F'?'a':'o');           
}

[...]

// Merge das assinaturas.
$TBS->MergeBlock('assinaturas', $this->hasPeritos);

And the template side, inside one cell:

[assinaturas.nome;block=table:table-cell]
Perit[assinaturas.desGen] Criminal

It is a field with signatures and the layout, I must to implement, has to be with signatures side by side, from one to many.
By: Skrol29
Date: 2012-07-12
Time: 10:13

Re: Generate multiple columns

Can you send the template to me ?
Or just a simplified template that reproduces the problem.
By: Fabio Rocha
Date: 2012-07-13
Time: 21:30

Re: Generate multiple columns

Sure. The simplified code I used to reproduce:

$hasPeritos = array();

$hasPeritos[1]['nome'] = 'Fabio';
$hasPeritos[1]['desGen'] = 'o';

$hasPeritos[2]['nome'] = 'Flavia';
$hasPeritos[2]['desGen'] = 'a';

include_once($path_to_tbs.'/tbs_class.php');
include_once($path_to_tbs.'/plugins/tbs_plugin_opentbs.php');

$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

$TBS->ResetVarRef(false); // VarRef is now a new empty array
$TBS->VarRef['hasPeritos'] = $hasPeritos;

$TBS->LoadTemplate('teste.odt', OPENTBS_ALREADY_UTF8);

$TBS->MergeBlock('assinaturas', $hasPeritos);

$TBS->Show(OPENTBS_FILE, 'gerado.odt');

I wil send the template to you as soon as I get your email. Anyway, it's just an odt file with one table and the tbs fields on it:

[assinaturas.nome;block=table:table-cell] - [assinaturas.desGen]

The same code runs fine with the docx template.

Thank you for your help.
By: Skrol29
Date: 2012-07-14
Time: 18:13

Re: Generate multiple columns

Hi Fabio,

Thank for your PHP snippet and your template file by email.
I've been able to reproduce the problem. You did not mention in the post that your template was ODT, I thought it was ODS.
I've edited the title of your post to give the precision.

So, the problem is that the table element (<table:table>) expects to have the number of columns defined with the <table:table-column> sub-elements.
One element <table:table-column> can declare one one several columns by its attribute "table:number-columns-repeated".

So you can place the following TBS field just after the table :
[assinaturas.#;att=table:table-column#table:number-columns-repeated]

This field is outside the block, thus [assinaturas.#] will be the number of record merged (equal to the number of column in your case).
And parameter "att" will move the field at the correct place for the attribute.

Don't forget to adjust the column width if needed.
By: Fabio Rocha
Date: 2012-07-16
Time: 18:49

Re: Generate multiple columns

You're right, I didn't mention about the odt. Thank you for the update.

You're right about the element table-column too. Modifying the template as you said solved the problem. Wish I can pay you back. Thank you.