Forum


Replies: 2   Views: 950
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 skinhat  · 29-12-2021 - 04:37

Im finding if I use a colspan like below in a table:

<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>

the output docx file is:

1 2 3 4

6 7

and is missing the last columns.

Im using Microsoft Word 365 (version 2111) and phpdocx premium-11.0-ns. Does display ok in Libre Office though

 

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.

Posted by skinhat  · 29-12-2021 - 08:11

Thanks. That works.