Skip to content

Commit

Permalink
Merge branch 'master' into wordunimplemented2
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman authored Sep 13, 2024
2 parents 90ee6a9 + fa0cea0 commit 63e9fd1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes/1.x/1.4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Enhancements

- Writer ODText: Support for ListItemRun by [@Progi1984](https://github.com/Progi1984) fixing [#2159](https://github.com/PHPOffice/PHPWord/issues/2159), [#2620](https://github.com/PHPOffice/PHPWord/issues/2620) in [#2669](https://github.com/PHPOffice/PHPWord/pull/2669)
- Writer HTML: Support for vAlign in Tables by [@SpraxDev](https://github.com/SpraxDev) in [#2675](https://github.com/PHPOffice/PHPWord/pull/2675)

### Bug fixes

Expand Down
3 changes: 3 additions & 0 deletions src/PhpWord/Writer/HTML/Style/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function write()
$css['direction'] = 'rtl';
}
}
if (is_object($style) && method_exists($style, 'getVAlign')) {
$css['vertical-align'] = $style->getVAlign();
}

foreach (['Top', 'Left', 'Bottom', 'Right'] as $direction) {
$method = 'getBorder' . $direction . 'Style';
Expand Down
27 changes: 26 additions & 1 deletion tests/PhpWordTests/Writer/HTML/Element/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use DOMXPath;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Writer\HTML\Element\Table;
use PhpOffice\PhpWord\SimpleType\VerticalJc;
use PhpOffice\PhpWordTests\Writer\HTML\Helper;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -162,4 +162,29 @@ public function testWriteTableBorders(): void
self::assertNotFalse(preg_match('/^[.]tstyle[^\\r\\n]*/m', $style, $matches));
self::assertEquals(".tstyle {table-layout: auto; $cssnone}", $matches[0]);
}

public function testWriteTableCellVAlign(): void
{
$phpWord = new PhpWord();
$section = $phpWord->addSection();

$table = $section->addTable();
$row = $table->addRow();

$cell = $row->addCell();
$cell->addText('top text');
$cell->getStyle()->setVAlign(VerticalJc::TOP);

$cell = $row->addCell();
$cell->addText('bottom text');
$cell->getStyle()->setVAlign(VerticalJc::BOTTOM);

$dom = Helper::getAsHTML($phpWord);
$xpath = new DOMXPath($dom);

$cell1Style = Helper::getTextContent($xpath, '//table/tr/td[1]', 'style');
$cell2Style = Helper::getTextContent($xpath, '//table/tr/td[2]', 'style');
self::assertSame('vertical-align: top;', $cell1Style);
self::assertSame('vertical-align: bottom;', $cell2Style);
}
}

0 comments on commit 63e9fd1

Please sign in to comment.