如何将下拉列表应用于给定的列范围或整个列 Laravel excel

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

您好,我正在使用 Maatwebsite/Laravel-Excel 包创建我的 excel sheet。我有很多下拉列表,我可以为特定的单元格添加它。我想在整个列或给定的列范围内添加下拉列表。你能指导我如何为整个栏目应用下拉列表吗?

看到这就是代码的和平

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

以上代码目前仅在单元格 E1 中放置下拉菜单。我如何指定特定的单元格范围以将下拉列表放入给定范围

您需要获取需要导出的行数。 然后试试,

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

要获取行数,请尝试使用 public 变量并在获取数据集时设置它。 例如。

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;
    }
}