Adding table layout to the generated HTML if element has layout style. This is useful when using creating PDF from PHPWord (e.g. using dompdf), otherwise the PDF does not contain any layout for table.
This commit is contained in:
parent
2bfd82e229
commit
e61c40e71d
|
|
@ -39,7 +39,9 @@ class Table extends AbstractElement
|
|||
$rows = $this->element->getRows();
|
||||
$rowCount = count($rows);
|
||||
if ($rowCount > 0) {
|
||||
$content .= '<table>' . PHP_EOL;
|
||||
$tableStyle = $this->element->getStyle();
|
||||
$tableLayout = $tableStyle === null ? '' : $tableStyle->getLayout();
|
||||
$content .= '<table'. (empty($tableLayout) ? '' : ' style="table-layout: '.$tableLayout.'"') .'>'. PHP_EOL;
|
||||
for ($i = 0; $i < $rowCount; $i++) {
|
||||
/** @var $row \PhpOffice\PhpWord\Element\Row Type hint */
|
||||
$rowStyle = $rows[$i]->getStyle();
|
||||
|
|
|
|||
|
|
@ -157,4 +157,23 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$this->assertTrue(strpos($content, $expected) !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests writing table with layout
|
||||
*/
|
||||
public function testWriteTableLayout()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
$section->addTable();
|
||||
$table = $section->addTable(array('layout' => 'fixed'));
|
||||
|
||||
$row1 = $table->addRow();
|
||||
$row1->addCell()->addText('fixed layout table');
|
||||
|
||||
$dom = $this->getAsHTML($phpWord);
|
||||
$xpath = new \DOMXPath($dom);
|
||||
|
||||
$this->assertEquals('table-layout: fixed', $xpath->query('/html/body/table')->item(0)->attributes->getNamedItem('style')->textContent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue