A BadMethodCallException occurs when I try to read a Word document
"Cannot add PreserveText in Section."
The document I'm trying to read does actually open in Word, so it looks like a check to add PreserveText to a Section is too strict.
I am having the same issue as well with a dotx file. Trying to read in a template and update placeholder text for saving as a word doc. Received the same error even though the document can be opened in MS Word.
ping @ivanlanin @RomanSyroeshko
This happens with most of the files I'm trying to open using . Any idea when this could be fixed? The Exception message sounds quite solvable ;)
Is this exception on adding a PreserveText to a Section a feature? Or is it not supported yet?
This happens on Word files that contain fields, as the ones used with the mail merge feature. As soon as those are removed, the file opens fine (they're easily removable with Ctrl+A, then Ctrl+Shift+F9). The exception is indeed thrown when trying to add a PreserveText object to a Section object. Lifting that restriction makes the document load, even thought the resulting PreserveText object doesn't behave as documented. (Its getText() returns some array instead of a string).
@jlherren I agree, but as our process is automated Word is not available to remove the fields. Basically what I mean is that the cached value of these fields should be used instead of triggering an exception.
PHPWord/src/PhpWord/Element/AbstractContainer.php in line 214. Change: 'PreserveText' => array('Header', 'Footer', 'Cell') into: 'PreserveText' => array('Section', 'Header', 'Footer', 'Cell')
@lductrung92 what about providing a PR for that 👍
@lductrung92 Thank you!
Most helpful comment
PHPWord/src/PhpWord/Element/AbstractContainer.php in line 214. Change: 'PreserveText' => array('Header', 'Footer', 'Cell') into: 'PreserveText' => array('Section', 'Header', 'Footer', 'Cell')