Forum


Replies: 4   Views: 6748
Remove indent from left on tables that come in via html
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  · 24-08-2016 - 07:24

Hello,

Thanks for the info. Then you need to remove the cell margin, not the table margin.

To do this you have three approaches:

1. Wrap the cell content in a paragrah and set a margin left negative value:

$html .= '<table border="1" style="border-collapse: collapse; border-left-width: 0px;" width="600">
  <tbody>
    <tr width="600">
      <td style="background-color: yellow;"><p style="margin-left:-7px;">1_1</p></td>
      <td rowspan="3" colspan="2">1_2</td>
    </tr>

2. Create a table style (with Word or phpdocx that sets this left margin as 0). This style can be used with embedHtml.

3. Apply a small patch in the file classes/HTML2WordML.inc (this patch was included in phpdocx 9.5). Around line 1809 (after //w:tblCellMar comment) please add these lines:

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

And now you can set a custom default padding:

$html .= '<table border="1" style="border-collapse: collapse;padding-left: 0px;" width="600">
            <tbody>
                <tr width="600">
                    <td style="background-color: yellow">1_1</td>
                    <td rowspan="3" colspan="2">1_2</td>
                </tr>

Regards.