Forum


Replies: 3   Views: 2303
Td width problem after 9.0 update
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 jusatuo  · 19-03-2019 - 23:34

Hi!

I updated to version 9.0 from 8 today.

After that

1) $docx->enableCompatibilityMode();  produced HTTP error 500

and after commenting that line

2) All table TD widths (defined either with css style or <td width="400">) didn't have effect anymore when embedding an HTML table. All had equal width. The table itself had correct width.

Any idea? Should I go back to 8.0?

Posted by admin  · 20-03-2019 - 09:06

Hello,

The enableCompatibilityMode method has been removed in phpdocx 9, as it's not used anymore. You can read this on the release notes: https://www.phpdocx.com/news/post/phpdocx-v9-release-notes/218

About your width question, some minutes ago we have uploaded a minor change to all packages of phpdocx 9 to prevent width issues when working with some versions of LibreOffice, maybe you are opening the DOCX with LibreOffice? Please download the package again from MY PHPDOCX, or if you want to do the same change to your current installation of phpdocx 9, please edit HTMLWordML.php and around line 1560 change these lines:

case 'tr':
    //Before closing a row we should make sure that there are no lacking cells due to a previous rowspan
    $row = count(self::$tableGrid[self::$openTable]) - 1;
    $column = count(self::$tableGrid[self::$openTable][$row]);
    $sRet .= $this->closeTr($row, $column);
    if (strpos($this->wordML, '#<w:gridCol/>#') !== false) {
        // get the cell width
        if (self::$tableGrid[self::$openTable][$row][$column][2]['width'] !== null) {
            list($cellWidth, $cellWidthType) = $this->_wordMLUnits(self::$tableGrid[self::$openTable][$row][$column][2]['width']);
        }

        if ($cellWidth) {
            $i = 0;
            foreach (self::$tableGrid[self::$openTable][$row] as $rowProperties) {
                list($cellWidth, $cellWidthType) = $this->_wordMLUnits($rowProperties[2]['width']);
                if (!isset($this->gridColValues[$i]) || $this->gridColValues[$i] > $cellWidth) {
                    $this->gridColValues[$i] = $cellWidth;
                }
                $i++;
            }
        }
    }
    //We now may close the tr tag
    $sRet .= '</w:tr>';
    break;

with:

case 'tr':
    //Before closing a row we should make sure that there are no lacking cells due to a previous rowspan
    $row = count(self::$tableGrid[self::$openTable]) - 1;
    $column = count(self::$tableGrid[self::$openTable][$row]);
    $sRet .= $this->closeTr($row, $column);
    if (strpos($this->wordML, '#<w:gridCol/>#') !== false) {
        // get the cell width
        if (self::$tableGrid[self::$openTable][$row][$column][2]['width'] !== null) {
            list($cellWidth, $cellWidthType) = $this->_wordMLUnits(self::$tableGrid[self::$openTable][$row][$column][2]['width']);
        } else if (self::$tableGrid[self::$openTable][$row][$row][2]['width'] !== null) {
            list($cellWidth, $cellWidthType) = $this->_wordMLUnits(self::$tableGrid[self::$openTable][$row][$row][2]['width']);
        }

        if ($cellWidth) {
            $i = 0;
            foreach (self::$tableGrid[self::$openTable][$row] as $rowProperties) {
                list($cellWidth, $cellWidthType) = $this->_wordMLUnits($rowProperties[2]['width']);
                if (!isset($this->gridColValues[$i]) || $this->gridColValues[$i] > $cellWidth) {
                    $this->gridColValues[$i] = $cellWidth;
                }
                $i++;
            }
        }
    }
    //We now may close the tr tag
    $sRet .= '</w:tr>';
    break;

The changed is that these three lines have been added:

else if (self::$tableGrid[self::$openTable][$row][$row][2]['width'] !== null) {
    list($cellWidth, $cellWidthType) = $this->_wordMLUnits(self::$tableGrid[self::$openTable][$row][$row][2]['width']);
}

And try again. After this minor chage the problem with some versions of LibreOffice is fixed.

Regards.

Posted by jusatuo  · 20-03-2019 - 10:42

Thank you for the fast response! The fix solved the problem.

Posted by admin  · 20-03-2019 - 11:40

Great :) The same change has been included in all packages of phpdocx 9, so all users of this version can get it just downloading the package available on MY PHPDOCX page.

Regards.