Replies: 1   Views: 1199
Custom table styles: left and right cell margins are ignored
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-08-2021 - 19:22


When transforming HTML to DOCX the following contents can add spacing in a cell: the cell itself and the paragraph added to the cell. We recommend you to check if that extra spacing is being added in the cell or in the paragraph added as content. The following styles apply spacings: margin and padding (please check you are not adding extra spacings with these styles).
Please also note that if you are applying a custom table style and want to ignore CSS styles as much as possible, you need to use strictWordStyles (as true) and addDefaultStyles (as false).
Using the previous options and the correct margin/padding values you can get the exact output you need.

About your question, you can use getWordStyles to get the styles applied to a custom style. From the sample included in the package (DocxPath/getWordStyles/sample_4.php):

$referenceNode = array(
    'type' => 'style',
    'contains' => 'ListParagraph',

$contents = $docx->getWordStyles($referenceNode);

that returns the styles applied to ListParagraph. You can replace it by any other style name. To get the cell margins in a custom table style you need to query by the w:tblCellMar style (w:top, w:left, w:bottom and w:right tags). Although you can get the style values using this code and apply them to the HTML/CSS, we think the easiest approach is setting the correct styles and options when transforming HTML, that allows to ignore unwanted styles and use the values from the custom styles.

If you open a support ticket ( attaching your DOCX template, the HTML you are transforming, and the code you are using to transform it (in all cases the most simple samples that illustrate your issue), the dev team will check them and generate a custom script using your template and HTML.