【问题标题】:Laravel Excel not downloadingLaravel Excel 没有下载
【发布时间】: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');
}

我已经尝试了在我的控制器中看到的两种方式都没有下载任何我看到的东西,如果我将扩展名更改为 xlsxlsx 数据是不可读的,因为有很多符号显示为好吧

我做错了什么?我怎样才能让它下载一个实际的 excel 文件?

【问题讨论】:

    标签: laravel laravel-excel


    【解决方案1】:

    解决方案是使用<a href=""/> 路由而不是使用方法,因为它在通过vue 发送请求时不起作用。其他代码是正确的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-02
      • 1970-01-01
      • 2020-03-09
      • 2020-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-08
      相关资源
      最近更新 更多