如何使用php在excel中创建下拉列表

时间:2017-03-31 07:11:07

标签: php excel phpexcel

我需要使用php在excel中创建一个下拉列表。实际上我需要将用户的输入限制为给定值。看看图像。 我已成功生成excel文件,但无法创建下拉列表。谷歌搜索没有帮助:)请看一下图像。提前致谢enter image description here

2 个答案:

答案 0 :(得分:0)

If you are using PHPEXCEL API to generate the excel sheet then you can use this:

please use this: $objPHPExcel->getActiveSheet()->setAutoFilter('A1:I20');

或者

$objPHPExcel->getActiveSheet()->setAutoFilter(
$objPHPExcel->getActiveSheet()->calculateWorksheetDimension()

);

答案 1 :(得分:0)

我发现解决方案如下:

                    $objValidation = $objPHPExcel->getActiveSheet()->getCell('B'.$i)->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('"Rate,Margin"');