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  · 05-01-2018 - 15:59

Hello,

The current version of phpdocx only allows using margin-top and margin-bottom for cells. You could MS Word custom styles to get the output you need, but the next version of phpdocx will include support for margin-left and margin-right for cells (other contents already support them).

It's current being tested, but if you want to test it, please edit the HTML2WordML.inc file and replace the tcPrSpacing method by these new code:

private function tcPrSpacing($properties)
{
    $top = $left = $bottom = $right = array(0, 'auto');

    if (!empty($properties['margin_top'])) {
        $top = $this->_wordMLUnits($properties['margin_top'], $properties['font_size']);
    }
    if (!empty($properties['padding_top'])) {
        $temp = $this->_wordMLUnits($properties['padding_top'], $properties['font_size']);
        if ($temp[0] > $top[0])
            $top = $temp;
    }

    if (!empty($properties['margin_bottom'])) {
        $bottom = $this->_wordMLUnits($properties['margin_bottom'], $properties['font_size']);
    }
    if (!empty($properties['padding_bottom'])) {
        $temp = $this->_wordMLUnits($properties['padding_bottom'], $properties['font_size']);
        if ($temp[0] > $bottom[0])
            $bottom = $temp;
    }

    if (!empty($properties['margin_left'])) {
        $left = $this->_wordMLUnits($properties['margin_left'], $properties['font_size']);
    }
    if (!empty($properties['padding_left'])) {
        $temp = $this->_wordMLUnits($properties['padding_left'], $properties['font_size']);
        if ($temp[0] > $left[0])
            $left = $temp;
    }

    if (!empty($properties['margin_right'])) {
        $right = $this->_wordMLUnits($properties['margin_right'], $properties['font_size']);
    }
    if (!empty($properties['padding_right'])) {
        $temp = $this->_wordMLUnits($properties['padding_right'], $properties['font_size']);
        if ($temp[0] > $right[0])
            $right = $temp;
    }

    $spacing = '<w:tcMar>';
    $spacing .= '<w:top w:w="' . $top[0] . '" w:type="' . $top[1] . '"/>';
    $spacing .= '<w:left w:w="' . $left[0] . '" w:type="' . $left[1] . '"/>';
    $spacing .= '<w:bottom w:w="' . $bottom[0] . '" w:type="' . $bottom[1] . '"/>';
    $spacing .= '<w:right w:w="' . $right[0] . '" w:type="' . $right[1] . '"/>';
    $spacing .= '</w:tcMar>';
    return $spacing;
}

After applying these changes, both left and right margins will work for cells.

Regards.