Forum


Replies: 5   Views: 3246
Html table default cellmarges
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  · 08-01-2018 - 08:40

Hello,

We have checked it again, and the output is correct.

After applying the previous code, if you run this sample script:

<?php

require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();
$html = '<table style="border:0px; float:right; width:100%; boder-spacing:0; border-collapse: collapse; text-align:right; margin:0; padding:0;" cellspacing="0" cellpadding="0">
        <tr valign="top" style="margin:0; padding:0;">
                <td style="margin:0; padding:0;">some data</td>
                <td style="margin:0; padding:0;">another data</td>
        </tr>
</table>';
$docx->embedHTML($html);

$docx->createDocx('output');

and then you open the DOCX with MS Word and go to the table properties and Cell Options, all margins are set to 0.

If we open the main document.xml file, we check directly that all margins of the cell are set to 0 as well:

<w:tc>
    <w:tcPr>
        <w:tcMar>
            <w:top w:type="auto" w:w="0"/>
            <w:left w:type="auto" w:w="0"/>
            <w:bottom w:type="auto" w:w="0"/>
            <w:right w:type="auto" w:w="0"/>
        </w:tcMar>
        <w:vAlign w:val="top"/>
    </w:tcPr>

Please check that the previous has been applied correctly and run the script of this update standalone. We have checked it with MS Word 2007, 2010, 2013 and 2016 and it's working fine.

Anyway, please note that you can use a custom MS Word style for the table if you prefer. There're samples of using this approach on https://www.phpdocx.com/documentation/introduction/html-to-word-PHP (Using native Word formatting with HTML section).

Regards.