Forum


Replies: 1   Views: 1270
Table style like at microsoft office
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  · 16-01-2020 - 11:37

Hello,

We recommed you to apply the border-collapse: collapse style:

$wordStyles = array(
    '<table>' => 'myTableStyle',
);

$html = '<table width="100%" style="border-collapse: collapse">
            <tbody>
                <tr>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                </tr>
                <tr>
                    <td>4</td>
                    <td>5</td>
                    <td>6</td>
                </tr>
            </tbody>
        </table>';
$docx->embedHTML($html, array('parseAnchors' => true, 'useHTMLExtended' => true, 'customListStyles' => true, 'wordStyles' => $wordStyles));

Otherwise, you need to remove the styles added as default using the strictWordStyles option, but this may require setting more styles to the content:

$wordStyles = array(
    '<table>' => 'myTableStyle',
);

$html = '<table width="100%">
            <tbody>
                <tr>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                </tr>
                <tr>
                    <td>4</td>
                    <td>5</td>
                    <td>6</td>
                </tr>
            </tbody>
        </table>';
$docx->embedHTML($html, array('parseAnchors' => true, 'useHTMLExtended' => true, 'customListStyles' => true, 'wordStyles' => $wordStyles, 'strictWordStyles' => true));

Regards.