I'm using Laravel Excel to export excel with larvel. I need a dropdown with multiple select.
use App\MyModel;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithHeadings;
class MyModelExport implements FromArray, WithHeadings
{
public $rowCount = 0;
public function array(): array
{
$branches = MyModel::get([
"title",
"ranks",
]);
$data = [];
foreach ($items $key => $item) {
$data[$key]['title'] = $item->title;
$data[$key]['ranks'] = $item->ranks;
}
$this->rowCount = count($data);
return $data;
}
public function registerEvents(): array {
return [
AfterSheet::class => function(AfterSheet $event) {
/** @var Sheet $sheet */
$sheet = $event->sheet;
/**
* validation for bulkuploadsheet
*/
for($i=2; $i<=$this->rowCount+1; $i++){
$sheet->setCellValue('B'.$i, $sheet->getCell('B'.$i)->getValue());
$configs = "dis1, dis 2, dis 3";
$objValidation = $sheet->getCell('B'.$i)->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 rank from the drop-down list.');
$objValidation->setFormula1('"' . $configs . '"');
}
},
];
}
public function headings(): array
{
return [
'Title',
'Ranks'
];
}
}
This code gives a dropdown. But what I need a dropdown with multiple selects. Simply I need to select multiple ranks in one cell.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire