Laravel excel library(Maatwebsite) : How to create a drop down list in exports

前端 未结 2 669
囚心锁ツ
囚心锁ツ 2021-01-17 14:56

I am creating an excel template which should contain a dropdown list. I see its possible with the phpexcel library (PHPExcel Multiple Dropdown list that dependent). I was w

2条回答
  •  半阙折子戏
    2021-01-17 15:51

    for maatwebite version V.3.1 use below code

     Category::all()
            ]);
        }
    
        public function title(): string
        {
            return 'bulkupload';
        }
    
        public function registerEvents(): array
        {
    
            //$event = $this->getEvent();
            return [
                AfterSheet::class => function (AfterSheet $event) {
                   
                    /** @var Sheet $sheet */
                    $sheet = $event->sheet;
    
                    /**
                     * validation for bulkuploadsheet
                     */
    
                    $sheet->setCellValue('B5', "SELECT ITEM");
                    $configs = "DUS800, DUG900+3xRRUS, DUW2100, 2xMU, SIU, DUS800+3xRRUS, DUG900+3xRRUS, DUW2100";
                    $objValidation = $sheet->getCell('B5')->getDataValidation();
                    $objValidation->setType(DataValidation::TYPE_LIST);
                    $objValidation->setErrorStyle(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('"' . $configs . '"');
                  
                }
            ];
        }
    }
    

提交回复
热议问题