From 6d21efc173b54e61fadeaaee971bfa219bf806c0 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Thu, 17 Oct 2013 11:19:20 +0100 Subject: [PATCH] Updated data validation example to show a list derived from data in the worksheet rather than from a comma-separated string --- Examples/15datavalidation.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Examples/15datavalidation.php b/Examples/15datavalidation.php index af49c6a..2b4745f 100644 --- a/Examples/15datavalidation.php +++ b/Examples/15datavalidation.php @@ -62,7 +62,15 @@ $objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data ->setCellValue('A3', "Number:") ->setCellValue('B3', "10") ->setCellValue('A5', "List:") - ->setCellValue('B5', "Item A"); + ->setCellValue('B5', "Item A") + ->setCellValue('A7', "List #2:") + ->setCellValue('B7', "Item #2") + ->setCellValue('D2', "Item #1") + ->setCellValue('D3', "Item #2") + ->setCellValue('D4', "Item #3") + ->setCellValue('D5', "Item #4") + ->setCellValue('D6', "Item #5") + ; // Set data validation @@ -91,7 +99,21 @@ $objValidation->setErrorTitle('Input error'); $objValidation->setError('Value is not in list.'); $objValidation->setPromptTitle('Pick from list'); $objValidation->setPrompt('Please pick a value from the drop-down list.'); -$objValidation->setFormula1('"Item A,Item B,Item C"'); // Make sure to put the list items between " and " !!! +$objValidation->setFormula1('"Item A,Item B,Item C"'); // Make sure to put the list items between " and " if your list is simply a comma-separated list of values !!! + + +$objValidation = $objPHPExcel->getActiveSheet()->getCell('B7')->getDataValidation(); +$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST ); +$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION ); +$objValidation->setAllowBlank(false); +$objValidation->setShowInputMessage(true); +$objValidation->setShowErrorMessage(true); +$objValidation->setShowDropDown(true); +$objValidation->setErrorTitle('Input error'); +$objValidation->setError('Value is not in list.'); +$objValidation->setPromptTitle('Pick from list'); +$objValidation->setPrompt('Please pick a value from the drop-down list.'); +$objValidation->setFormula1('$D$2:$D$6'); // Make sure NOT to put a range of cells or a formula between " and " !!! // Set active sheet index to the first sheet, so Excel opens this as the first sheet