Skip to content

Commit fda4498

Browse files
Luke LanchesterPowerKiKi
authored andcommitted
Re-add support for reading nested tables
This commit re-adds supports for nested tables as provided by @mathieuweber in PR #571
1 parent 34eb13b commit fda4498

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ protected function readTable(XMLReader $xmlReader, DOMElement $domNode, $parent,
376376
foreach ($cellNodes as $cellNode) {
377377
if ('w:p' == $cellNode->nodeName) { // Paragraph
378378
$this->readParagraph($xmlReader, $cellNode, $cell, $docPart);
379+
} elseif ($cellNode->nodeName == 'w:tbl') { // Table
380+
$this->readTable($xmlReader, $cellNode, $cell, $docPart);
379381
}
380382
}
381383
}

tests/PhpWordTests/Reader/Word2007/ElementTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,38 @@ public function testReadTitleStyle(): void
277277
self::assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $formattedTitle->getText());
278278
}
279279

280+
/**
281+
* Test reading of nested table
282+
*/
283+
public function testReadNestedTable()
284+
{
285+
$documentXml = '<w:tbl>
286+
<w:tr>
287+
<w:tc>
288+
<w:tbl>
289+
<w:tr>
290+
<w:tc>
291+
<w:p>
292+
<w:t>${Field}</w:t>
293+
</w:p>
294+
</w:tc>
295+
</w:tr>
296+
</w:tbl>
297+
<w:p />
298+
</w:tc>
299+
</w:tr>
300+
</w:tbl>';
301+
302+
$phpWord = $this->getDocumentFromString(array('document' => $documentXml));
303+
304+
$section = $phpWord->getSection(0);
305+
$table = $section->getElement(0);
306+
$rows = $table->getRows();
307+
$cells = $rows[0]->getCells();
308+
$nestedTable = $cells[0]->getElement(0);
309+
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Table', $nestedTable);
310+
}
311+
280312
/**
281313
* Test reading Drawing.
282314
*/

0 commit comments

Comments
 (0)