diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index f8a0b11324..53bb7ed752 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1206,6 +1206,8 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet foreach ($shapes as $shape) { /** @var SimpleXMLElement $shape */ $shape->registerXPathNamespace('v', Namespaces::URN_VML); + $shape->registerXPathNamespace('x', Namespaces::URN_VML); + $shape->registerXPathNamespace('o', Namespaces::URN_MSOFFICE); if (isset($shape['style'])) { $style = (string) $shape['style']; diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4505Test.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4505Test.php new file mode 100644 index 0000000000..fc859bf578 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4505Test.php @@ -0,0 +1,80 @@ +load(self::$file); + $sheet = $spreadsheet->getActiveSheet(); + + $comments = $sheet->getComments(); + self::assertSame('Sheet1', $sheet->getTitle()); + + if (!empty($comments)) { + $comment = reset($comments); + $comment->getText(); + } + + $spreadsheet->disconnectWorksheets(); + } + + public function testVmlFileContainsRequiredNamespaces(): void + { + $file = 'zip://' . self::$file . '#xl/drawings/vmlDrawing1.vml'; + $data = file_get_contents($file); + + if ($data === false) { + self::markTestSkipped('Test file issue.4505.xlsx not found or VML file missing.'); + } + + self::assertStringContainsString('registerXPathNamespace('v', XlsxNamespaces::URN_VML); + $shape->registerXPathNamespace('x', XlsxNamespaces::URN_VML); + $shape->registerXPathNamespace('o', XlsxNamespaces::URN_MSOFFICE); + + $clientData = $shape->xpath('.//x:ClientData'); + self::assertNotEmpty($clientData, 'XPath with x: prefix works with namespace registration'); + + $relid = $shape->xpath('.//v:fill/@o:relid'); + self::assertNotEmpty($relid, 'XPath with o: prefix works with namespace registration'); + + $row = $clientData[0]->xpath('.//x:Row'); + self::assertNotEmpty($row, 'Can access nested x: elements'); + self::assertEquals('5', (string) $row[0], 'Row value is correct'); + + self::assertEquals('rId1', (string) $relid[0], 'RelId value is correct'); + } +} diff --git a/tests/data/Reader/XLSX/issue.4505.xlsx b/tests/data/Reader/XLSX/issue.4505.xlsx new file mode 100644 index 0000000000..9b0a417b59 Binary files /dev/null and b/tests/data/Reader/XLSX/issue.4505.xlsx differ