Open matschek opened 2 years ago
I took a look at the XML of the documents and it seems the one where no TextBox is detected, the content is in another node than the libary is looking for. I made a quick guess and fix which works for my purpose but may not respect all things like it should.
In AbstractPart.php I inserted an if..else to differ between an image and a textbox
<?php
# AbstractPart.php, line 252
} elseif ($node->nodeName == 'w:pict') {
/* begin of new code part */
// Textbox
$textbox = $xmlReader->getElement('v:shape/v:textbox', $node);
if (null !== $textbox) {
$new_txtbx = $parent->addTextBox();
$txbxContent_wp = $xmlReader->getElements('w:txbxContent/w:p', $textbox);
foreach ($txbxContent_wp as $wp) {
$this->readParagraph($xmlReader, $wp, $new_txtbx, $docPart);
}
} else {
// Image
/* end of new code part */
To allow this to work I had to make another change and allow a TextBox to be inserted in a TextRun, which is forbidden by default. I don't know why and if it breaks other things :-/
<?php
# AbstractContainer, line 245:
'TextBox' => array('Section', 'Header', 'Footer', 'Cell', 'TextRun'), /*+TextRun*/
Hope this helps to develop the real fix.
It was usefull
thanks!
Describe the Bug
Reading different files in Word 2007 format, I either get TextBoxes as standard Text elements or I don't get the element at all.
Steps to Reproduce
Sample document with the text "Normal text (ok)" in the body, and a textfield with the text "textfield within body".
Expected Behavior
Expecting the textfield as PhpOffice\PhpWord\Element\TextBox object, acting as a container with other elements inside.
Current Behavior
Result for "textbox-problem-fail.docx": Textfield element and its content is completely missing. Found 1 elements in body-container Element PhpOffice\PhpWord\Element\TextRun: Found container with 1 subElements SubElement PhpOffice\PhpWord\Element\Text: Normal text (ok)
Result for "textbox-problem-ok.docx": Textfield is returned as standard Text element. At least, we get the text here. Found 1 elements in body-container Element PhpOffice\PhpWord\Element\TextRun: Found container with 2 subElements SubElement PhpOffice\PhpWord\Element\Text: textfield within body (OK) SubElement PhpOffice\PhpWord\Element\Text: Normal text (ok)
Context