Forum


Replies: 2   Views: 1699
Margins are set to 0 when converting a html table to word
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  · 09-09-2020 - 16:48

Hello,

The current version of phpdocx sets default values to cell margins (using a custom table style or not), so you need to overwrite them with padding properties if you want to set custom values. 

The testing branch adds the following change (not available in the stable branch):

if (!$this->strictWordStyles) {
    if (isset($properties['padding_left']) || isset($properties['padding_right'])) {
        $stringTblPr .='<w:tblCellMar>';
            if (isset($properties['padding_left'])) {
                $paddingLeftValue = $this->_wordMLUnits($properties['padding_left']);
                $stringTblPr .= '<w:left w:type="dxa" w:w="'.$paddingLeftValue[0].'"/>';
            }
            if (isset($properties['padding_right'])) {
                $paddingRightValue = $this->_wordMLUnits($properties['padding_right']);
                $stringTblPr .= '<w:right w:type="dxa" w:w="'.$paddingRightValue[0].'"/>';
            }
        $stringTblPr .='</w:tblCellMar>';
    }
}

So no padding value is added to w:tblCellMar if strictWordStyles is set to true. This change will be added to the next stable version of phpdocx (there's no release date); you can apply the same change to phpdocx 10 in generateTblPr.

Other approach, that doesn't require changing the library, is using DOCXPath (https://www.phpdocx.com/api-documentation/docx-path/remove-elements-in-docx) to remove that cell margins, but we think the first solution is the easiest one.

Regards.