diff --git a/src/PhpSpreadsheet/Reader/Xls.php b/src/PhpSpreadsheet/Reader/Xls.php index 3825471808..13af96889a 100644 --- a/src/PhpSpreadsheet/Reader/Xls.php +++ b/src/PhpSpreadsheet/Reader/Xls.php @@ -3749,12 +3749,10 @@ private function readLabelSst(): void } else { $textRun = $richText->createTextRun($text); if (isset($fmtRuns[$i - 1])) { - if ($fmtRuns[$i - 1]['fontIndex'] < 4) { - $fontIndex = $fmtRuns[$i - 1]['fontIndex']; - } else { - // this has to do with that index 4 is omitted in all BIFF versions for some strange reason - // check the OpenOffice documentation of the FONT record - $fontIndex = $fmtRuns[$i - 1]['fontIndex'] - 1; + $fontIndex = $fmtRuns[$i - 1]['fontIndex']; + + if (array_key_exists($fontIndex, $this->objFonts) === false) { + $fontIndex = count($this->objFonts) - 1; } $textRun->setFont(clone $this->objFonts[$fontIndex]); } diff --git a/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php b/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php index 942576948a..2cd14a87c0 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php @@ -121,4 +121,13 @@ public function testLoadMacCentralEurope2(): void self::assertSame('Ładowność', $sheet->getCell('I1')->getValue()); $spreadsheet->disconnectWorksheets(); } + + public function testLoadXlsBug1114(): void + { + $filename = 'tests/data/Reader/XLS/bug1114.xls'; + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); + $sheet = $spreadsheet->getActiveSheet(); + self::assertSame(1148140800.0, $sheet->getCell('B2')->getValue()); + $spreadsheet->disconnectWorksheets(); + } } diff --git a/tests/data/Reader/XLS/bug1114.xls b/tests/data/Reader/XLS/bug1114.xls new file mode 100644 index 0000000000..ae12a11e44 Binary files /dev/null and b/tests/data/Reader/XLS/bug1114.xls differ