Categories > OpenTBS with DOCX >

Using opentbs for docx file with diff table contents on each instance

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Gene
Date: 2010-12-08
Time: 23:01

Using opentbs for docx file with diff table contents on each instance

I would like to use opentbs to generate docx file with one page for each user, with user name at top and a 2-column table on the page with different data for each user.
I see examples of tables on the site for html, but nothing like this for docx files.
Is there an example you can point me to - I would like to see the docx template and the php code.
Thanks!
By: Skrol29
Date: 2010-12-09
Time: 00:45

Re: Using opentbs for docx file with diff table contents on each instance

Hi Gene,

The demo provided on line and within the OpenTbs package give a DOCX example with table.
By: Gene
Date: 2010-12-09
Time: 15:11

Re: Using opentbs for docx file with diff table contents on each instance

Yes, true, but that table shows its contents on only one page and only one time. I need a table on each page with different elements in the table for each page.
Any examples of this?
Thanks!
By: Skrol29
Date: 2010-12-09
Time: 16:03

Re: Using opentbs for docx file with diff table contents on each instance


There is no such example for DOCX, but it is the same as for other template types:
Use a block for merging each user name on one page (the DOCX example show how to do one record per page), and a sub-block for merging user information on the table.
They are two types of sub-block: automatic sub-block, and sub-block with dynamic query.
You have online examples of sub-blocks with HTML, it's the same principal for DOCX.
By: Gene
Date: 2010-12-09
Time: 17:24

Re: Using opentbs for docx file with diff table contents on each instance

Ok I tried it and am getting:

TinyButStrong Error in block's definition [asb.team...]: a least one tag with parameter 'block=end' is missing.

Any idea what I am doing wrong?

The docx is defined as below with the items starting Position Town Score Date all in a docx table and the block=end outside and below the table:

Team: [asb.team;block=begin;sub1=matches] , Total score: [asb.total]
Position    Town    Score    Date
[asb_sub1.#]    [asb_sub1.town;block=w:tr]    [asb_sub1.score]    [asb_sub1.date;frm='mm-dd-yyyy']
[asb_sub1.#]    [asb_sub1.town;block=w:tr]    [asb_sub1.score]    [asb_sub1.date;frm='mm-dd-yyyy']


[asb.team ;block=end ;comm=w :p]


and the php is:
$TeamList[0] = array('team'=>'Eagle'  ,'total'=>'458');
$TeamList[0]['matches'][] = array('town'=>'London','score'=>'253','date'=>'1999-11-30');
$TeamList[0]['matches'][] = array('town'=>'Paris' ,'score'=>'145','date'=>'2002-07-24');
$TeamList[1] = array('team'=>'Goonies','total'=>'281');
$TeamList[1]['matches'][] = array('town'=>'New-York','score'=>'365','date'=>'2001-12-25');
$TeamList[1]['matches'][] = array('town'=>'Madrid'  ,'score'=>'521','date'=>'2004-01-14');
$TeamList[2] = array('team'=>'MIB'    ,'total'=>'615');
$TeamList[2]['matches'][] = array('town'=>'Dallas'    ,'score'=>'362','date'=>'2001-01-02');
$TeamList[2]['matches'][] = array('town'=>'Lyon'      ,'score'=>'321','date'=>'2002-11-17');
$TeamList[2]['matches'][] = array('town'=>'Washington','score'=>'245','date'=>'2003-08-24');

// Automatic subblock
$TBS->MergeBlock('asb',$TeamList);

Thanks!
By: Skrol29
Date: 2010-12-09
Time: 18:07

Re: Using opentbs for docx file with diff table contents on each instance

It seems that your final tag [asb.team ;block=end ;comm=w :p] is not recognized.

By the way, "comm=w :p" is not good, it should be "comm=w:p".
If that doesn't fix the problem, this is probably because this last TBS tag is not formated as you may assume inside the XML. It may happen that Ms Word split the XML in order to insert spell checks or versioning marks.
The template example, provided with the OpenTBS demo, explains how to workaround such issues.
You can check your TBS tags in the deep XML using the OpenTBS debug mode. The debug mode is explain in the documentation.

By: Gene
Date: 2010-12-09
Time: 19:37

Re: Using opentbs for docx file with diff table contents on each instance

Ok, I used the debug mode and I am getting many lines like this at the beginning of the trace:
<b>Warning</b>:  str_repeat() [<a href='function.str-repeat'>function.str-repeat</a>]: Second argument has to be greater than or equal to 0 in <b>/hermes/web09/b1561/moo.compug1/tbs_plugin_opentbs.php</b> on line <b>377</b><br />
and when I try to open the created file I get message
"There was an error opening the file".
Have you any idea what could be causing this? By the way, in the trace I do see that substitution was done, as here:
<w:rPr>
  <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
  <w:sz w:val="24"/>
  <w:szCs w:val="24"/>
  <w:lang w:val="en-US"/>
</w:rPr>
<w:t>
  Washington
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>


Thanks again for your responses on this!
By: Skrol29
Date: 2010-12-10
Time: 11:04

Re: Using opentbs for docx file with diff table contents on each instance

The warning message you've got is a new bug of the debug mode. It will be fixed in the next release, and can be avoid by replacing
str_repeat(' ',$lev)
with
str_repeat(' ',max($lev,0))
in the OpenTBS source file. (the item appears twice in the code)

Could you do the debug mode again but before, turn the MergeBlock() on 'asb' in comment? Then search in the debug listing the [asb.team;block=end;comm=w:p] item and check it it is broken with XML or not.
By: Gene
Date: 2010-12-10
Time: 14:38

Re: Using opentbs for docx file with diff table contents on each instance

Thanks for the info. Here is what I get when I do what you suggested:
<w:p w:rsidR="003254BD" w:rsidRDefault="003254BD"/>
  <w:p w:rsidR="003254BD" w:rsidRDefault="003254BD">
   <w:r>
    <w:t>
      [asb.team;block=end;comm=w:p]
    </w:t>
   </w:r>
  </w:p>
  <w:p w:rsidR="003254BD" w:rsidRDefault="003254BD">
Can you tell if there is a problem there?
By: Skrol29
Date: 2010-12-10
Time: 14:56

Re: Using opentbs for docx file with diff table contents on each instance

The TBS tag is not broken. So I don't understand why you've got this error message.
Is it possible for you to send your template to me, so I'll be able to reproduce it?
By: Gene
Date: 2010-12-10
Time: 15:40

Re: Using opentbs for docx file with diff table contents on each instance

Ok, php code and docx template have been sent to your e-mail address.
Please let me know when you get them and what you can find out.
I greatly appreciate your work on this!
Gene
By: Skrol29
Date: 2010-12-10
Time: 22:25

Re: Using opentbs for docx file with diff table contents on each instance

hi Gene,

I has a look at the files you sent to me.
I can figure out the problem, it seems more obvious now.

First, you must now use sub-names for the TBS tags that have "block=begin" or "block=end".
It should be structured like this:
[asb;block=begin;sub1=matches]
...
[asb;block=end]

The second thing is that the XML structure is broken when you define [asb.team;block=begin;sub1=matches] inside a piece of text.
The other TBS tags that use "block=begin" or "block=end" also have a parameter "comm=w:p". This parameter extends the bounds of the tags, and so makes the block start (or end) to be positioned at the same level as a paragraph.

By: Gene
Date: 2010-12-12
Time: 15:42

Re: Using opentbs for docx file with diff table contents on each instance

Ok, I updated the template as you suggested and I am not getting error message now, but the substitutions are not being done;
I sent you latest template via e-mail.
Gene
By: Gene
Date: 2010-12-14
Time: 20:37

Re: Using opentbs for docx file with diff table contents on each instance

Please disregard previous post.
I got it working, thanks very much for your help! You've got great software here!

By the way, are you offering your forum code at all for download and use by others? It says somewhere that it is available
on your download page but I didn't find it there.

Gene
By: Skrol29
Date: 2010-12-14
Time: 23:07

Re: Using opentbs for docx file with diff table contents on each instance

> By the way, are you offering your forum code at all for download and use by others?

It should be available soon.
This is a new stable version but I have to actualize the documentation.