Forum


Replies: 1   Views: 3560
Replacevariablebyhtml and 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 michealorion  · 30-11-2016 - 15:12

Deleted by michealorion · 05-12-2016 - 09:52

Posted by admin  · 30-11-2016 - 17:27

Hello,

The method replaceVariableByHTML allows to replace a placeholder by a HTML, transforming the HTML to Word. You can use almost any tag and CSS style to add contents and style them.

For example you can set width of the whole table:

$html = '<table border="1" style="border-collapse: collapse" width="400">
            <tbody>
                <tr>
                    <td style="background-color: yellow">1_1</td>
                    <td rowspan="3" colspan="2">1_2</td>
                </tr>
                <tr>
                    <td>Some random text.</td>
                </tr>
                <tr>
                    <td>
                        <ul>
                            <li>One</li>
                            <li>Two <b>and a half</b></li>
                        </ul>
                    </td>
                </tr>
            </tbody>
        </table>';

$docx->replaceVariableByHTML('VAR', 'inline', $html, array('isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false));

This code uses the attribute width, but you can use CSS as well.

We recommend you to read the documentation available on:

http://www.phpdocx.com/documentation/introduction/html-to-word-PHP

http://www.phpdocx.com/documentation/cookbook/convert-html-to-word

and the examples included in the package.

Regards.