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 协议》,转载必须注明作者和本文链接