Replies: 4   Views: 6787
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 unita  · 23-08-2016 - 06:28


I was wondering if there is a way to remove the 0.12" left indent on tables? Currently when i add a table with 0 margin/border/padding it still leaves an indent from the left on it in word. This is adding a table via html.


Posted by admin  · 23-08-2016 - 07:02


Please post the most simple script that illustrates your issue and if Tidy is enabled and running. Also, please run the included example Core/embedHTML/sample_1.php that adds a tablet without indentations.

The style margin-left allows to set 0 as table indentation, but this always if the option strictWordStyles isn't true.


Posted by unita  · 24-08-2016 - 02:08

Hi, I can confirm that i have tried everything said below

I have made an image describing the issue and have shown the code (margin and padding left)

Also strictWordStyle is set to false otherwise it doesn't display correctly.

Posted by admin  · 24-08-2016 - 07:24


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">
    <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>

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/ (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">
                <tr width="600">
                    <td style="background-color: yellow">1_1</td>
                    <td rowspan="3" colspan="2">1_2</td>


Posted by unita  · 24-08-2016 - 23:54

I made the change to that file and it worked. Thanks!