From ef99fac8e1a69989c7a3db19b3be0ba3eef8e094 Mon Sep 17 00:00:00 2001 From: Yohann Tilotti Date: Fri, 6 Jan 2023 16:26:34 +0100 Subject: [PATCH] Add support table row height when importing HTML (#2350) * Add support table row height when importing HTML * fix space * fix phpcsfixer * Add test table row height * Fix xpath test table row height * Fix attribute first test table row height * Fix $cValue Co-authored-by: Progi1984 * Fix css * Fix test on pt Co-authored-by: Progi1984 --- src/PhpWord/Shared/Html.php | 11 +++++- tests/PhpWordTests/Shared/HtmlTest.php | 52 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index b0fcfb9e..0b351585 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -444,7 +444,11 @@ class Html $rowStyles['tblHeader'] = true; } - return $element->addRow(null, $rowStyles); + // set cell height to control row heights + $height = $rowStyles['height'] ?? null; + unset($rowStyles['height']); // would not apply + + return $element->addRow($height, $rowStyles); } /** @@ -808,6 +812,11 @@ class Html $styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::AUTO; } + break; + case 'height': + $styles['height'] = Converter::cssToTwip($value); + $styles['exactHeight'] = true; + break; case 'border': case 'border-top': diff --git a/tests/PhpWordTests/Shared/HtmlTest.php b/tests/PhpWordTests/Shared/HtmlTest.php index 8da6ccc6..7340b219 100644 --- a/tests/PhpWordTests/Shared/HtmlTest.php +++ b/tests/PhpWordTests/Shared/HtmlTest.php @@ -464,6 +464,58 @@ HTML; self::assertEquals('dxa', $doc->getElement($xpath)->getAttribute('w:type')); } + /** + * Parse heights in rows, which also allows for controlling column height. + */ + public function testParseTableRowHeight(): void + { + $phpWord = new PhpWord(); + $section = $phpWord->addSection([ + 'orientation' => \PhpOffice\PhpWord\Style\Section::ORIENTATION_LANDSCAPE, + ]); + + $html = << + + 100px + + + 200pt + + + + + + + +
300px
+ + + +HTML; + + Html::addHtml($section, $html); + $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); + + // elementExists($xpath)); + self::assertEquals(4000, $doc->getElement($xpath)->getAttribute('w:val')); + self::assertEquals('exact', $doc->getElement($xpath)->getAttribute('w:hRule')); + + //