Can I -> Dropdown List OR Type Anything?

Topics: User Forum
Nov 9, 2011 at 4:20 PM

I'm trying to make a cell take a drop down list from a Named Range but if the user wants to just type something that isn't in the list they can, or they can leave it blank.

The dropdown is for their convenience, not for validation.

Can I do that with PHPExcel?

Nov 9, 2011 at 5:55 PM

Well, it turns out that I can.

$excel->setActiveSheetIndex(0);
    $objValidation = $excel->getActiveSheet()->getCell("A2")->getDataValidation();
    $objValidation->setFormula1('ListsSheet!$A$1:$A$12');
    $objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
    $objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION );
    $objValidation->setAllowBlank(true);
    $objValidation->setShowInputMessage(false);
    $objValidation->setShowErrorMessage(false);
    $objValidation->setShowDropDown(true);

I just setAllowBlank to true, made the validation style STYLE_INFORMATION and set the messages to false.
I'm not sure exactly which properties permitted it, I'm guessing STYLE_INFORMATION but I can select from the drop down or just type in whatever I want or leave it blank.