mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-05 06:58:15 +00:00
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:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user