diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 562e7fe81..7c870e1ed 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -84,6 +84,8 @@ $config '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 @@ $config '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 53bb7ed75..44685c474 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1205,9 +1205,10 @@ class Xlsx extends BaseReader $shapes = self::xpathNoFalse($vmlCommentsFile, '//v:shape'); 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); + $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']; @@ -1232,6 +1233,7 @@ class Xlsx extends BaseReader $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 index fc859bf57..51ca078fb 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4505Test.php +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4505Test.php @@ -5,13 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; -use PhpOffice\PhpSpreadsheet\Reader\Xlsx\Namespaces as XlsxNamespaces; use PHPUnit\Framework\TestCase; -use SimpleXMLElement; class Issue4505Test extends TestCase { - private static string $file = 'tests/data/Reader/XLSX/issue.4505.xlsx'; + private static string $file = 'tests/data/Reader/XLSX/issue.4505.namespace.xlsx'; public function testVmlProcessingWithXAndONamespaces(): void { @@ -20,61 +18,24 @@ class Issue4505Test extends TestCase $sheet = $spreadsheet->getActiveSheet(); $comments = $sheet->getComments(); - self::assertSame('Sheet1', $sheet->getTitle()); - - if (!empty($comments)) { - $comment = reset($comments); - $comment->getText(); - } - + 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 = file_get_contents($file); + $data = (string) 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'); + 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 000000000..043f9eaa7 Binary files /dev/null and b/tests/data/Reader/XLSX/issue.4505.namespace.xlsx differ diff --git a/tests/data/Reader/XLSX/issue.4505.xlsx b/tests/data/Reader/XLSX/issue.4505.xlsx deleted file mode 100644 index 9b0a417b5..000000000 Binary files a/tests/data/Reader/XLSX/issue.4505.xlsx and /dev/null differ