Merge pull request #3352 from PHPOffice/PR3329-Additional-Exception-Handling

Additional exception handling to prevent an invalid formula from breaking `isDateTime()`
This commit is contained in:
Mark Baker
2023-02-07 20:43:32 +01:00
committed by GitHub
2 changed files with 21 additions and 7 deletions
+12 -7
View File
@@ -375,13 +375,18 @@ class Date
if ($worksheet !== null && $spreadsheet !== null) {
$index = $spreadsheet->getActiveSheetIndex();
$selected = $worksheet->getSelectedCells();
$result = is_numeric($value ?? $cell->getCalculatedValue()) &&
self::isDateTimeFormat(
$worksheet->getStyle(
$cell->getCoordinate()
)->getNumberFormat(),
$dateWithoutTimeOkay
);
try {
$result = is_numeric($value ?? $cell->getCalculatedValue()) &&
self::isDateTimeFormat(
$worksheet->getStyle(
$cell->getCoordinate()
)->getNumberFormat(),
$dateWithoutTimeOkay
);
} catch (Exception $e) {
// Result is already false, so no need to actually do anything here
}
$worksheet->setSelectedCells($selected);
$spreadsheet->setActiveSheetIndex($index);
}
@@ -262,5 +262,14 @@ class DateTest extends TestCase
->getNumberFormat()
->setFormatCode('0.00E+00');
self::assertFalse(null !== $cella3 && Date::isDateTime($cella3));
$cella4 = $sheet->getCell('A4');
self::assertNotNull($cella4);
$cella4->setValue('= 44 7510557347');
$sheet->getStyle('A4')
->getNumberFormat()
->setFormatCode('yyyy-mm-dd');
self::assertFalse(Date::isDateTime($cella4));
}
}