diff --git a/src/PhpSpreadsheet/Reader/Xml.php b/src/PhpSpreadsheet/Reader/Xml.php index e4d251e28f..11aa1df3bd 100644 --- a/src/PhpSpreadsheet/Reader/Xml.php +++ b/src/PhpSpreadsheet/Reader/Xml.php @@ -617,9 +617,11 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet) ++$rowID; } - $xmlX = $worksheet->children($namespaces['x']); - if (isset($xmlX->WorksheetOptions)) { - (new PageSettings($xmlX, $namespaces))->loadPageSettings($spreadsheet); + if (isset($namespaces['x'])) { + $xmlX = $worksheet->children($namespaces['x']); + if (isset($xmlX->WorksheetOptions)) { + (new PageSettings($xmlX, $namespaces))->loadPageSettings($spreadsheet); + } } } ++$worksheetID; diff --git a/tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php b/tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php new file mode 100644 index 0000000000..e0b43113b1 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php @@ -0,0 +1,70 @@ +filename) { + unlink($this->filename); + $this->filename = ''; + } + } + + public function testWriteThenRead(): void + { + $xmldata = <<< 'EOT' + + + + Xml2003 Short Workbook + + + 2 + + + 9000 + 13860 + 240 + 75 + False + False + + + + + + + Test String 1 + + +
+
+
+EOT; + $this->filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test'); + file_put_contents($this->filename, $xmldata); + $reader = new Xml(); + $spreadsheet = $reader->load($this->filename); + self::assertEquals(1, $spreadsheet->getSheetCount()); + + $sheet = $spreadsheet->getActiveSheet(); + self::assertEquals('Sample Data', $sheet->getTitle()); + self::assertEquals('Test String 1', $sheet->getCell('A8')->getValue()); + + $props = $spreadsheet->getProperties(); + self::assertEquals('Xml2003 Short Workbook', $props->getTitle()); + self::assertEquals('2', $props->getCustomPropertyValue('myŚInt')); + } +}