diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 8ae685037b..db4a34c4b4 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -940,7 +940,10 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet } $node->addAttribute('sqref', $item->children(Namespaces::DATA_VALIDATIONS2)->sqref); if (isset($item->formula1)) { - $node->addChild('formula1', $item->formula1->children(Namespaces::DATA_VALIDATIONS2)->f); + $childNode = $node->addChild('formula1'); + if ($childNode !== null) { // null should never happen + $childNode[0] = (string) $item->formula1->children(Namespaces::DATA_VALIDATIONS2)->f; // @phpstan-ignore-line + } } } } diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue3145Test.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue3145Test.php new file mode 100644 index 0000000000..b7d3a4cc71 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue3145Test.php @@ -0,0 +1,23 @@ +load($filename); + $sheet = $spreadsheet->getActiveSheet(); + + self::assertEquals('Headline A', $sheet->getCell('A1')->getValue()); + self::assertEquals('Configdential B', $sheet->getCell('A2')->getValue()); + self::assertSame('OFFSET(INDIRECT(SUBSTITUTE($A2," ","")),0,0,COUNTA(INDIRECT(SUBSTITUTE($A2," ","")&"Col")),1)', $sheet->getCell('B2')->getDataValidation()->getFormula1()); + + $spreadsheet->disconnectWorksheets(); + } +} diff --git a/tests/data/Reader/XLSX/issue.3145.xlsx b/tests/data/Reader/XLSX/issue.3145.xlsx new file mode 100644 index 0000000000..9fd3646245 Binary files /dev/null and b/tests/data/Reader/XLSX/issue.3145.xlsx differ