Hello.
First of all, I would like to thank you very much for your work. OpenTBS is an amazing, very useful and very powerful tool.
Thank you for all the energy you have invested in this project, thank you for sharing it for free, and thank you to be still present on this forum and helping users.
I wanted to evoke a bug I encountered using OpenTBS to generate Word 2010 documents including tables filled dynamically with a non predefined number of columns.
Moreover, it happens when the "AutoFit to Contents" option from table menu is enabled. This is annoying as this option is very useful for dynamic tables.
When there are not too many columns it works well, the width fits the content. However, if there is too much, the size does not fit in, it keeps the original one when the cell contained the OpenTBS's block and this causes a distortion of the table which exceeds the size of the Word sheet chaotically.
My DOCX Template is a 2 rows and 1 column simple table:
[head.title;block=tbs:cell;parallel=tbs:table]
[body.[head.title];block=tbs:row] |
My PHP script looks like this (I added custom parameters used to see when the bug shows up):
$head = array();
$body = array();
$nb_columns = 8;
$nb_rows = 2;
$cell_length = 7;
for ($i = 0; $i < $nb_columns; $i++) {
$title = substr(md5(rand()), 0, $cell_length);
$head[] = array("title" => $title);
}
for ($i = 0; $i < $nb_rows; $i++) {
$row = array();
for ($j = 0; $j < $nb_columns; $j++) {
$title = $head[$j]["title"];
$value = substr(md5(rand()), 0, $cell_length);
$row[$title] = $value;
}
$body[] = $row;
}
$TBS->LoadTemplate('template.docx');
$TBS->MergeBlock("head", $head);
$TBS->MergeBlock("body", $body);
$TBS->Show(OPENTBS_FILE, "report.docx"); |
From the few tests I conducted, I noticed:
- The number of rows does not seem to have any influence
- The size of contents does not seem to have any influence
- The margin page does not seem to have any influence
Nevertheless, the cells left and right margins (accessed from options of table properties) have an influence: the less it is, the more the number of columns can be without bug.
Examples:
- 0.05 cm (default value) -> Max columns = 8
- 0.00 cm -> Max columns = 9
- 1.00 cm -> Max columns = 7
For now, I have no other way but to set the width of the cells to a small value, and activate the autofit by hand after generating the document. This is not very convenient because I use a lot of dynamic tables.
I wanted to know if this bug was known, and if a fix or workaround was possible?
Thank you in advance!