【发布时间】:2020-04-17 14:21:43
【问题描述】:
这是我目前拥有的 导出类
class ReportExcel implements FromArray, withHeadings
{
use Exportable;
protected $items;
public function __construct(array $items)
{
$this->items= $items;
}
public function headings(): array
{
return ["Opcion 1", "Opcion 2", "Opcion 3", "Nombres", "Apellidos", "Telefono", "Correo",
"Pais", "Pais Otro", "Edad", "Adventista", "Estudia la Biblia", "Peticion", "Fecha"];
}
public function array(): array
{
return $this->items;
}
}
我的控制器中的方法
public function downloadExcel(Request $request)
{
if ($request->country == null) {
$item = Form::get(['option_1', 'option_2', 'option_3', 'name', 'lastname', 'phone',
'email', 'country_id', 'country_other', 'age', 'adventist', 'study', 'petition', 'date_answered']);
} else {
$item = Form::where('country_id', $request->country)->orderByDesc('created_at')
->get(['option_1', 'option_2', 'option_3', 'name', 'lastname', 'phone', 'email', 'country_id',
'country_other', 'age', 'adventist', 'study', 'petition', 'date_answered']);
}
$items[] = $item;
// return (new ReportExcel($items))->download('invoices.csv', Excel::CSV,
// ['Content-Type' => 'text/csv']);
return Excel::download(new ReportExcel($items), 'reporte.csv');
}
我已经尝试了在我的控制器中看到的两种方式都没有下载任何我看到的东西,如果我将扩展名更改为 xls 或 xlsx 数据是不可读的,因为有很多符号显示为好吧
我做错了什么?我怎样才能让它下载一个实际的 excel 文件?
【问题讨论】:
标签: laravel laravel-excel