Forum


Replies: 3   Views: 2264
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 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.