diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 562e7fe81b..7c870e1ed6 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -84,6 +84,8 @@ 'method_chaining_indentation' => true, 'modernize_strpos' => true, 'modernize_types_casting' => true, + 'modifier_keywords' => ['elements' => ['property', 'method']], // not const + 'multiline_comment_opening_closing' => true, 'multiline_whitespace_before_semicolons' => true, 'native_constant_invocation' => false, // Micro optimization that look messy @@ -236,7 +238,6 @@ 'types_spaces' => true, 'unary_operator_spaces' => true, 'use_arrow_functions' => true, - 'visibility_required' => ['elements' => ['property', 'method']], // not const 'void_return' => true, 'whitespace_after_comma_in_array' => true, 'yoda_style' => false, diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index f8a0b11324..44685c474d 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1205,7 +1205,10 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $shapes = self::xpathNoFalse($vmlCommentsFile, '//v:shape'); foreach ($shapes as $shape) { /** @var SimpleXMLElement $shape */ - $shape->registerXPathNamespace('v', Namespaces::URN_VML); + $vmlNamespaces = $shape->getNamespaces(); + $shape->registerXPathNamespace('v', $vmlNamespaces['v'] ?? Namespaces::URN_VML); + $shape->registerXPathNamespace('x', $vmlNamespaces['x'] ?? Namespaces::URN_EXCEL); + $shape->registerXPathNamespace('o', $vmlNamespaces['o'] ?? Namespaces::URN_MSOFFICE); if (isset($shape['style'])) { $style = (string) $shape['style']; @@ -1230,6 +1233,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $clientData = $clientData[0]; if (isset($clientData['ObjectType']) && (string) $clientData['ObjectType'] == 'Note') { + $clientData->registerXPathNamespace('x', $vmlNamespaces['x'] ?? Namespaces::URN_EXCEL); $temp = $clientData->xpath('.//x:Row'); if (is_array($temp)) { $row = $temp[0]; diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4505Test.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4505Test.php new file mode 100644 index 0000000000..51ca078fb6 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4505Test.php @@ -0,0 +1,41 @@ +load(self::$file); + $sheet = $spreadsheet->getActiveSheet(); + + $comments = $sheet->getComments(); + self::assertArrayHasKey('A1', $comments); + self::assertSame('right', $comments['A1']->getAlignment()); + self::assertSame("Some User:\nHello", (string) $comments['A1']->getText()); + $spreadsheet->disconnectWorksheets(); + } + + public function testVmlFileContainsRequiredNamespaces(): void + { + $file = 'zip://' . self::$file . '#xl/drawings/vmlDrawing1.vml'; + $data = (string) file_get_contents($file); + + self::assertStringContainsString('', $data); // usually o:shapelayout v:ext + self::assertStringContainsString('', $data); // usually x:ClientData + self::assertStringContainsString('ns3:insetmode', $data); // usually o:insetmode + self::assertStringContainsString( + 'Right', // usually x:TextHAlign + $data + ); + } +} diff --git a/tests/data/Reader/XLSX/issue.4505.namespace.xlsx b/tests/data/Reader/XLSX/issue.4505.namespace.xlsx new file mode 100644 index 0000000000..043f9eaa7d Binary files /dev/null and b/tests/data/Reader/XLSX/issue.4505.namespace.xlsx differ