Laravel 5 如何使用Laravel Excel创建下拉列表

Laravel 5 如何使用Laravel Excel创建下拉列表,laravel-5,laravel-excel,Laravel 5,Laravel Excel,我试着用laravel excel创建下拉列表,但下载后下拉列表似乎并没有出现,甚至并没有抛出错误 代码如下: $excelsheet->sheet('ClassBoardData',函数($sheet1)使用($cc、$highrowofclass、$highrowofboard){ $variantsSheet=$sheet1->_parent->getSheet(1); $range='B1:B'。$highrowofclass $sheet1->_par

我试着用laravel excel创建下拉列表,但下载后下拉列表似乎并没有出现,甚至并没有抛出错误

代码如下: $excelsheet->sheet('ClassBoardData',函数($sheet1)使用($cc、$highrowofclass、$highrowofboard){ $variantsSheet=$sheet1->_parent->getSheet(1); $range='B1:B'。$highrowofclass

              $sheet1->_parent->addNamedRange(new \PHPExcel_NamedRange('classdata', $variantsSheet, $range));


            $objValidation = $sheet1->getCell('A1')->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 the list.');
            $objValidation->setPromptTitle('Pick from the list');
            $objValidation->setPrompt('Please pick a value from the drop-down list.');
            $objValidation->setFormula1('classdata');
        });

我发现,当使用Maatwebsite的Laravel Excel时,
addNamedRange
无法按预期工作

你必须改变:

$objValidation->setFormula1('classdata');
致:

其中,ProductList是您的工作表名称,A2:A7是单元格

$objValidation->setFormula1('ProductList!$A$2:$A$7');