PHPExcel Validation data length [Resolved]

Topics: Developer Forum
Oct 2, 2013 at 8:59 AM
Hi,
I've a problem to make simple data validation on data lentgh...

$formule = '"=NBCAR(A1)<6"';
$objValidation = $objPHPExcel->getActiveSheet()->getCell('A1')->getDataValidation();
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP );
$objValidation->setAllowBlank(false);
$objValidation->setShowErrorMessage(true);
$objValidation->setErrorTitle('Error length');
$objValidation->setError('Limited to 6');
$objValidation->setFormula1($formule);

Any idea please ?

Thanks

Sorry for my poor english :)
Oct 2, 2013 at 12:23 PM
The formulas must be in English. Try with LEN in this case.
Oct 3, 2013 at 9:45 AM
Thanks for reply :)
I've tested with LEN, but it doesn't works...

$formule = '"=LEN(A1)<6"';
$objValidation = $objPHPExcel->getActiveSheet()->getCell('A1')->getDataValidation();
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP );
$objValidation->setAllowBlank(false);
$objValidation->setShowErrorMessage(true);
$objValidation->setErrorTitle('Error length');
$objValidation->setError('Limited to 6');
$objValidation->setFormula1($formule);
Oct 3, 2013 at 10:01 AM
So good, I found the solution in PHPExcel/cell/DataValidation.php structure
With TYPE_TEXTLENGTH and OPERATOR_LESSTHAN variables

This code limit the length of the cell to 6 :

$objValidation = $objPHPExcel->getActiveSheet()->getCell('A1')->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_TEXTLENGTH );
$objValidation->setOperator(PHPExcel_Cell_DataValidation::OPERATOR_LESSTHAN );
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP );
$objValidation->setAllowBlank(false);
$objValidation->setShowErrorMessage(true);
$objValidation->setErrorTitle('Erreur de saisie');
$objValidation->setError('Le nombre de caractères est limité à 6');
$objValidation->setFormula1('6');

We can close this thread :)