如何在laravel中以maatwebsite/excel 3.1导出时动态标题
如何动态标题功能,如下所示如何在laravel中以maatwebsite/excel 3.1导出时动态标题,laravel,Laravel,如何动态标题功能,如下所示 class ExportPrescriptionReports implements FromCollection, WithHeadings { protected $names; protected $start_date; protected $end_date; protected $names_count; public function __construct(array $names, $start_d
class ExportPrescriptionReports implements FromCollection, WithHeadings
{
protected $names;
protected $start_date;
protected $end_date;
protected $names_count;
public function __construct(array $names, $start_date, $end_date)
{
$this->names = $names;
$this->start_date = $start_date;
$this->end_date = $end_date;
$this->names_count = count($names);
}
public function collection()
{
if($this->names_count == 2){
$name = $this->names[0];
$name1 = $this->names[1];
return Rsm_Prescription::select($name, $name1)
->where([
['start_data_time', $this->start_date],
['end_data_time', $this->end_date],
])->get();
}
}
public function headings(): array
{
return [
'SL No',
'Total Rx',
'Total Target Rx',
];
}
}
是否可以在laravel的maatwebsite excel包中使用?请任何人帮助我
你好。把代码放在
`
和image之间。qrabno-你知道任何解决方案。不,可能不知道。这个问题太糟糕了。最好的办法是你给我举一个完整的例子,让我自己试试!因此,对于输入、编译命令、输出、错误堆栈跟踪等,qrabno-我已经做到了,感谢您的响应
public function headings(): array
{
return [
$sl_no=0,
foreach($this->names as $name){
echo $sl_no;
echo $name;
$sl_no++;
}
]
}