Forum


Replies: 1   Views: 538
Html table with colspans
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by sandeepguntaka  · 14-06-2021 - 15:11

Hi,

I am trying to generate a table from html 

<?php
require_once '../../../Classes/Phpdocx/Create/CreateDocx.php';
$docx = new Phpdocx\Create\CreateDocx();
$html = '<table>
<tbody>
<tr>
<th>AAAAA</th>
<th>BBBBB</th>
<th>CCCCC</th>
<th>DDDDD</th>
</tr>
<tr>
<td colspan="3">111111</td>
<td>EEEEEE</td>
</tr>
<tr>
<td colspan="3">222222</td>
<td>FFFFFF</td>
</tr>
</tbody>
</table>';
$docx->embedHTML($html);
$docx->createDocx('example_embedHTML_1');

But the generated word ducument has a table with only 3 columns and rows with extra height.

https://ibb.co/GTpJg76

I am using a premium licence.

Is this issue already reported? I would like know the fix. Can someone help?

Posted by admin  · 14-06-2021 - 15:28

Hello,

Your username doesn't a license tied. Please send to contact[at]phpdocx.com the username or email that purchased the license.

About your question, MS Word can handle many automatic values when adding tables, but some cases such as the one you have posted, requires setting widths (the table itself and at least the first row) instead of automatic values, so MS Word can display the table correctly. Please check the following sample after changing your code:

$docx = new CreateDocx();

$html = '<table width="600">
<tbody>
<tr>
<th width="150">AAAAA</th>
<th width="150">BBBBB</th>
<th width="150">CCCCC</th>
<th width="150">DDDDD</th>
</tr>
<tr>
<td colspan="3">111111</td>
<td>EEEEEE</td>
</tr>
<tr>
<td colspan="3">222222</td>
<td>FFFFFF</td>
</tr>
</tbody>
</table>'
;

$docx->embedHTML($html);

$docx->createDocx('output');

Following this recommendation, all your tables will be displayed correctly.

Regards.