Reputation: 437
If I use:
$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('"male,female"');
to create an excel file, I get the following errors on windows Excel
1. We found a problem with some content in 'filename.xlsx'. Do you want to recover....
2. Removed Feature: Data validation from /xl/worksheets/shee1.xml part
If I comment that code out it opens normally.
Works as expected on Ubuntu Libre Office.
Upvotes: 2
Views: 2058
Reputation: 212522
This is all explained in the PHPExcel documentation
And if you look at the examples such as 15datavalidation.php
, it demonstrates how to create List type data validations
$objValidation = $objPHPExcel->getActiveSheet()
->getCell('B5')
->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION );
...
$objValidation->setFormula1('"Item A,Item B,Item C"');
shows how to create a list of fixed values
$objValidation = $objPHPExcel->getActiveSheet()
->getCell('B7')
->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION );
...
$objValidation->setFormula1('$D$2:$D$6');
shows how to create a list using a formula
Example 39dropdown.php
even shows how to created linked lists, where the values in one list are dependent on the selected value of another
Upvotes: 2