匯出類實現WithEvents
implements WithEvents
事件註冊
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 協議》,轉載必須註明作者和本文連結