Forum


Replies: 8   Views: 7349
Setting fixed width to first column in an html table
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  · 21-12-2017 - 16:16

Hello,

We have done some tests and everything is working as expected.

If we transform this simple HTML:

$html = '<table>
            <tbody>
                <tr>
                    <td width="180">FY 1</td>
                    <td width="180">FY 2</td>
                    <td width="180">FY 3</td>
                    <td width="180">FY 4</td>
                    <td width="100">FY 5</td>
                </tr>
                <tr>
                    <td>Content A1</td>
                    <td>Content A2</td>
                    <td>Content A3</td>
                    <td>Content A4</td>
                    <td>Content A5</td>
                </tr>
                <tr>
                    <td>Content B1</td>
                    <td>Content B2</td>
                    <td>Content B3</td>
                    <td>Content B4</td>
                    <td>Content B5</td>
                </tr>
                <tr>
                    <td>Content C1</td>
                    <td>Content C2</td>
                    <td>Content C3</td>
                    <td>Content C4</td>
                    <td>Content C5</td>
                </tr>
                <tr>
                    <td>Content D1</td>
                    <td>Content D2</td>
                    <td>Content D3</td>
                    <td>Content D4</td>
                    <td>Content D5</td>
                </tr>
            </tbody>
        </table>';

$docx->embedHTML($html);

and then we open the DOCX output with MS Word, all cells have the correct sizes. Please test the previous HTML standalone and check the output with MS Word (are you using another program to open the DOCX?).

We think there may be two issues in your code: the class tbl-summary is adding some extra style or some content has a very long word without spaces. By default, MS Word increases a cell size to fit the content if there's some word without spaces that doesn't fit in the cell width (such as 'thisisaverylongwordaddedtoacell').

If you use the addTable method you could set the fitText option to true to avoid this default behavior of MS Word, but the transformation from HTML to Word doesn't support it. DOCXCustomizer can inject this tag to any cell in a DOCX, but it's only available in Premium licenses.

If after following these recommendations you still have issues, please send to contact[at]phpdocx.com the most simple script that illustrates your issue (without doing external connections such as databases or web services) and the DOCX output you get. Also please attach the template if using any.

Regards.