laravel-excel导出excel下拉选择框

导出类实现 WithEvents#

implements WithEvents

事件注册#

/**
     * 通过事件机制,对 excel 的字段进行一些限制
     * @inheritDoc
     */
    public function registerEvents(): array
    {
        return [
            AfterSheet::class => function(AfterSheet $event) {
                $sheet = $event->sheet;
                $col = 'F';
                $list = ['投保', '自定义']
                $count = count($this->data) + 2;
                for ($i = 2; $i <= $count; $i++) {
                    $key = $col . $i;
                    $validation = $sheet->getDelegate()->getCell($key)->getDataValidation();
                    $validation->setType(DataValidation::TYPE_LIST);
                    $validation->setErrorStyle(DataValidation::STYLE_INFORMATION);
                    $validation->setAllowBlank(false);
                    $validation->setShowInputMessage(true);
                    $validation->setShowErrorMessage(true);
                    $validation->setShowDropDown(true);
                    $validation->setErrorTitle('');
                    $validation->setError('');
                    $validation->setPromptTitle('');
                    $validation->setPrompt('');
                    $validation->setFormula1('"' . implode(',', $list) . '"');
                }
            },
        ];
    }
本作品采用《CC 协议》,转载必须注明作者和本文链接
爱余生
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。