laravellaravel-excel

how to apply dropdown list to given column range or entire column Laravel excel


Hi There I am using Maatwebsite/Laravel-Excel package to create my excel sheet. i have many dropdown list and i am able to add it for particular cell. i want to add drop down in entire column or in the give column range. can you please guide me how to apply drop down list for entire column please ?

see this is the peace of code

$objValidation2 = $sheet->getCell('E1')->getDataValidation();

above code currently puts drop down in cell E1 only. how can i specify particular cell range to put drop down in the given range


Solution

  • You need to get the row count you need to export. then try,

    for($i=1; $i<=$this->rowCount; $i++){
       $objValidation2 = $sheet->getCell('E'.$i)->getDataValidation();
    }
    

    For getting row count try using public variable and set it when take the dataset. For example.

    namespace App\Exports;
    
    use App\Invoice;
    use Maatwebsite\Excel\Concerns\FromCollection;
    
    class InvoicesExport implements FromCollection
    {
        public $rowCount = 0;
        public function collection()
        {   
            $invoices = Invoice::all()
            $this->rowCount = invoices->count(); 
            return $invoices;
        }
    }