From dc050af9e2bd73d32567a489c40dfad0671548bb Mon Sep 17 00:00:00 2001 From: Xiang <1105462001@qq.com> Date: Wed, 13 Aug 2025 17:26:49 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8DIOFactory::save=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Writer/AbstractWriter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index 13859d8227..10eb565426 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -373,7 +373,7 @@ protected function addFileToPackage($zipPackage, $source, $target): void $zip = new ZipArchive(); if ($zip->open($zipFilename) !== false) { - if ($zip->locateName($imageFilename)) { + if ($zip->locateName($imageFilename) !== false) { $zip->extractTo($this->getTempDir(), $imageFilename); $actualSource = $this->getTempDir() . DIRECTORY_SEPARATOR . $imageFilename; } From cdbf0b2c01c33cd06935e9605d76fbeee52d691e Mon Sep 17 00:00:00 2001 From: Xiang <1105462001@qq.com> Date: Wed, 20 Aug 2025 15:19:16 +0800 Subject: [PATCH 2/5] =?UTF-8?q?Reader/Word2007/AbstractPart.php::readRunCh?= =?UTF-8?q?ild=E5=9B=BE=E7=89=87=E6=A0=B7=E5=BC=8F=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Reader/Word2007/AbstractPart.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 9d49573d69..995aa9cdf0 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -509,6 +509,21 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract $endnote = $parent->addEndnote(); $endnote->setRelationId($wId); } elseif ($node->nodeName == 'w:pict') { + $imageStyle=null; + $pictStyle = $xmlReader->getAttribute('style', $node, 'v:shape'); + if ($pictStyle!=null){ + $imageStyle=[]; + foreach (explode(';', $pictStyle) as $attribute){ + if (!empty($attribute)){ + [$attributeKey,$attributeVal] = explode(':',$attribute); + $attributeKey = str_replace('-', ' ', $attributeKey); + $attributeKey = ucwords($attributeKey); + $attributeKey = str_replace(' ', '', $attributeKey); + $attributeVal = preg_replace('/\s*pt\s*/', '', $attributeVal); + $imageStyle[$attributeKey]=$attributeVal; + } + } + } // Image $rId = $xmlReader->getAttribute('r:id', $node, 'v:shape/v:imagedata'); $target = $this->getMediaTarget($docPart, $rId); @@ -518,7 +533,7 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract } else { $imageSource = "zip://{$this->docFile}#{$target}"; } - $parent->addImage($imageSource); + $parent->addImage($imageSource,$imageStyle); } } elseif ($node->nodeName == 'w:drawing') { // Office 2011 Image From 5dd0216fdad8eccc1001cd2699a3df1e6d586ce9 Mon Sep 17 00:00:00 2001 From: Xiang <1105462001@qq.com> Date: Thu, 28 Aug 2025 14:47:21 +0800 Subject: [PATCH 3/5] =?UTF-8?q?Reader/Word2007/AbstractPart.php::readParag?= =?UTF-8?q?raph=20textbox=E6=96=87=E6=9C=AC=E4=B8=A2=E5=A4=B1=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Reader/Word2007/AbstractPart.php | 37 ++++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 995aa9cdf0..b723c0d880 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -262,6 +262,29 @@ protected function readParagraph(XMLReader $xmlReader, DOMElement $domNode, $par } $parent->addPreserveText(htmlspecialchars($textContent, ENT_QUOTES, 'UTF-8'), $fontStyle, $paragraphStyle); + return; + } elseif ($xmlReader->elementExists('w:r/w:pict/v:shape/v:textbox', $domNode)) { + //textbox + $shapeStyle=null; + $_style = $xmlReader->getAttribute('style', $domNode, 'w:r/w:pict/v:shape'); + if ($_style!=null){ + $shapeStyle=[]; + foreach (explode(';', $_style) as $attribute){ + if (!empty($attribute)){ + [$attributeKey,$attributeVal] = explode(':',$attribute); + $attributeKey = str_replace('-', ' ', $attributeKey); + $attributeKey = ucwords($attributeKey); + $attributeKey = str_replace(' ', '', $attributeKey); + $attributeVal = preg_replace('/\s*pt\s*/', '', $attributeVal); + $shapeStyle[$attributeKey]=$attributeVal; + } + } + } + $textBox = $parent->addTextBox($shapeStyle); + $nodes = $xmlReader->getElements('w:r/w:pict/v:shape/v:textbox/w:txbxContent/*', $domNode); + foreach ($nodes as $_node){ + $this->readParagraph($xmlReader,$_node,$textBox,$docPart); + } return; } @@ -509,18 +532,18 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract $endnote = $parent->addEndnote(); $endnote->setRelationId($wId); } elseif ($node->nodeName == 'w:pict') { - $imageStyle=null; - $pictStyle = $xmlReader->getAttribute('style', $node, 'v:shape'); - if ($pictStyle!=null){ - $imageStyle=[]; - foreach (explode(';', $pictStyle) as $attribute){ + $shapeStyle=null; + $_style = $xmlReader->getAttribute('style', $node, 'v:shape'); + if ($_style!=null){ + $shapeStyle=[]; + foreach (explode(';', $_style) as $attribute){ if (!empty($attribute)){ [$attributeKey,$attributeVal] = explode(':',$attribute); $attributeKey = str_replace('-', ' ', $attributeKey); $attributeKey = ucwords($attributeKey); $attributeKey = str_replace(' ', '', $attributeKey); $attributeVal = preg_replace('/\s*pt\s*/', '', $attributeVal); - $imageStyle[$attributeKey]=$attributeVal; + $shapeStyle[$attributeKey]=$attributeVal; } } } @@ -533,7 +556,7 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract } else { $imageSource = "zip://{$this->docFile}#{$target}"; } - $parent->addImage($imageSource,$imageStyle); + $parent->addImage($imageSource,$shapeStyle); } } elseif ($node->nodeName == 'w:drawing') { // Office 2011 Image From 72cf409fe52ec7c47ca1f9cefe4c3180780b98c8 Mon Sep 17 00:00:00 2001 From: Xiang <1105462001@qq.com> Date: Fri, 29 Aug 2025 13:50:23 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Reader/Word2007/AbstractPart.php::readParag?= =?UTF-8?q?raph=20textbox=E5=B1=85=E4=B8=AD=E6=A0=B7=E5=BC=8F=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Reader/Word2007/AbstractPart.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index b723c0d880..deef105c6c 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -280,6 +280,9 @@ protected function readParagraph(XMLReader $xmlReader, DOMElement $domNode, $par } } } + if (is_array($paragraphStyle) && count($paragraphStyle)>0){ + $shapeStyle = array_merge($shapeStyle, $paragraphStyle); + } $textBox = $parent->addTextBox($shapeStyle); $nodes = $xmlReader->getElements('w:r/w:pict/v:shape/v:textbox/w:txbxContent/*', $domNode); foreach ($nodes as $_node){ From 0ca293b3c96c00d345073596469b54f2f8549033 Mon Sep 17 00:00:00 2001 From: Xiang <1105462001@qq.com> Date: Tue, 2 Sep 2025 10:47:54 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PhpWord/Reader/Word2007/AbstractPart.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index deef105c6c..bd835f48cf 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -266,10 +266,10 @@ protected function readParagraph(XMLReader $xmlReader, DOMElement $domNode, $par } elseif ($xmlReader->elementExists('w:r/w:pict/v:shape/v:textbox', $domNode)) { //textbox $shapeStyle=null; - $_style = $xmlReader->getAttribute('style', $domNode, 'w:r/w:pict/v:shape'); - if ($_style!=null){ + $styleVal = $xmlReader->getAttribute('style', $domNode, 'w:r/w:pict/v:shape'); + if ($styleVal!=null){ $shapeStyle=[]; - foreach (explode(';', $_style) as $attribute){ + foreach (explode(';', $styleVal) as $attribute){ if (!empty($attribute)){ [$attributeKey,$attributeVal] = explode(':',$attribute); $attributeKey = str_replace('-', ' ', $attributeKey); @@ -285,8 +285,8 @@ protected function readParagraph(XMLReader $xmlReader, DOMElement $domNode, $par } $textBox = $parent->addTextBox($shapeStyle); $nodes = $xmlReader->getElements('w:r/w:pict/v:shape/v:textbox/w:txbxContent/*', $domNode); - foreach ($nodes as $_node){ - $this->readParagraph($xmlReader,$_node,$textBox,$docPart); + foreach ($nodes as $node){ + $this->readParagraph($xmlReader,$node,$textBox,$docPart); } return; } @@ -536,10 +536,10 @@ protected function readRunChild(XMLReader $xmlReader, DOMElement $node, Abstract $endnote->setRelationId($wId); } elseif ($node->nodeName == 'w:pict') { $shapeStyle=null; - $_style = $xmlReader->getAttribute('style', $node, 'v:shape'); - if ($_style!=null){ + $styleVal = $xmlReader->getAttribute('style', $node, 'v:shape'); + if ($styleVal!=null){ $shapeStyle=[]; - foreach (explode(';', $_style) as $attribute){ + foreach (explode(';', $styleVal) as $attribute){ if (!empty($attribute)){ [$attributeKey,$attributeVal] = explode(':',$attribute); $attributeKey = str_replace('-', ' ', $attributeKey);