I am using PhpSpreadsheet within a Laravel app to output a spreadsheet that needs fairly strict controls around it in order to allow that same spreadsheet to be input back into the app after data has been entered.
I can control the data types and even have a nice pop-up message when a user enters an incorrect type such as this:
However, once the user clicks OK or Cancel, the incorrectly formatted text is allowed to remain in the cell. Is there a way to not only flag it for the user, but disallow the incorrect entry altogether?
Current example code:
if($sub['type'] === 'date') {
$ws->getStyle('C' . $row)->getNumberFormat()->setFormatCode(
\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DMYSLASH
);
$objValidation = $ws->getCell('C' . $row)->getDataValidation();
$objValidation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_DATE);
$objValidation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION);
$objValidation->setAllowBlank(true);
$objValidation->setShowInputMessage(true);
$objValidation->setShowErrorMessage(true);
$objValidation->setShowDropDown(true);
$objValidation->setErrorTitle('Input error');
$objValidation->setError('Please enter a date in the format d/m/yy only.');
}
I'm guessing I've missed something in the PhpSpreadsheet manual? I've looked into the base code on some of the methods like setAllowBlank
, but I'm likely not looking in the right place.