I tried the code on this page (codeplex phpexcel validation issue for invalid values) to validate input of numeric characters only. I also searched on the PHPExcel developer documentation and similar code appears. But when I applied it with my code and tested it, the cell does not accept even numeric characters.. may you suggest other methods on filtering or validating data input to numeric characters only.
The code below is from the PHPExcel developer documentation:
$objValidation = $objPHPExcel->getActiveSheet()->getCell('B3')
->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_WHOLE );
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP );
$objValidation->setAllowBlank(true);
$objValidation->setShowInputMessage(true);
$objValidation->setShowErrorMessage(true);
$objValidation->setErrorTitle('Input error');
$objValidation->setError('Number is not allowed!');
$objValidation->setPromptTitle('Allowed input');
$objValidation->setPrompt('Only numbers between 10 and 20 are allowed.');
$objValidation->setFormula1(10);
$objValidation->setFormula2(20);
I was having the very same issue and finally determined by trial & error that it was due to the cell format being set to text and not number that was causing the problem. Adding
just prior to your $objValidation will solve the problem. Of course you'll need to set the format to what ever applies to your situation. In this case I just need a whole number.
Your code only needs to set the operation to perform; Also do not forget to create the Writer with Excel2007 not with Excel5.
Something like this: