From b209fec72bd277c0452d4f5891c31f320612dc2a Mon Sep 17 00:00:00 2001 From: Nishant Bhatt Date: Mon, 3 Jun 2019 15:44:10 +0200 Subject: [PATCH 1/2] To suport preseve text inside sub container if we use preseve text inside table, issue fix https://stackoverflow.com/questions/33070424/phpword-cannot-add-preservetext-in-section --- src/PhpWord/Element/AbstractContainer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index 204d4a7399..74aabb1928 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -254,7 +254,7 @@ private function checkValidity($method) // Special condition, e.g. preservetext can only exists in cell when // the cell is located in header or footer $validSubcontainers = array( - 'PreserveText' => array(array('Cell'), array('Header', 'Footer')), + 'PreserveText' => array(array('Cell'), array('Header', 'Footer', 'Section')), 'Footnote' => array(array('Cell', 'TextRun'), array('Section')), 'Endnote' => array(array('Cell', 'TextRun'), array('Section')), ); From d7ed18c39db077aeb212598c1216a0068867296e Mon Sep 17 00:00:00 2001 From: troosan Date: Fri, 14 Jun 2019 00:19:44 +0200 Subject: [PATCH 2/2] fix test --- tests/PhpWord/Element/CellTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PhpWord/Element/CellTest.php b/tests/PhpWord/Element/CellTest.php index d4aaa48888..db0bae5c11 100644 --- a/tests/PhpWord/Element/CellTest.php +++ b/tests/PhpWord/Element/CellTest.php @@ -231,7 +231,7 @@ public function testAddPreserveTextNotUTF8() public function testAddPreserveTextException() { $oCell = new Cell(); - $oCell->setDocPart('Section', 1); + $oCell->setDocPart('TextRun', 1); $oCell->addPreserveText('text'); }