Forum


Replies: 2   Views: 987
Using colspan makes last column disappear
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 admin  · 29-12-2021 - 07:50

Hello,

MS Word can handle a limited number of columns with automatic widths. As general recommendation (https://www.phpdocx.com/documentation/cookbook/convert-html-to-word) when importing HTML with tables, please set the cell widths of at least the first row, and they will appear correctly in all DOCX readers. For example using width attributes:

$html = '
<table>
   <tr><td width="100">1</td><td width="100">2</td><td width="100">3</td><td width="100">4</td><td width="100">5</td></tr>
   <tr><td>6</td><td colspan="3">7</td><td>8</td></tr>
 </table>
';

$docx->embedHTML($html);

Or CSS styles:

$html = '
<style>
table tr:first-child td {
    width: 50px;
}
</style>
<table>
   <tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr>
   <tr><td>6</td><td colspan="3">7</td><td>8</td></tr>
 </table>';

$docx->embedHTML($html);

Regards.