Laravel-excel: [问题] - 如何更改默认工作表名称?

创建于 2018-03-26  ·  2评论  ·  资料来源: Maatwebsite/Laravel-Excel

版本

  • PHP 版本:7.1.9
  • Laravel 版本:5.5
  • 包版本:3.0

描述

我找不到如何更改文档中的工作表名称以将数据导出到 excel 文件。
我想根据我将提供的数据更改它,而不是使用 Worksheet 作为默认工作表名称。

感谢这个优秀的包裹。

我的代码

/** Voucher Export Class **/
namespace Modules\VoucherManagement\Exports;

use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use App\Models\Voucher;

class VouchersExport implements FromView
{    
    /**
     * <strong i="15">@return</strong> View
     */
    public function view(): View
    {
        $vouchers = Voucher::getAllVouchers();

        return view('templates.export', [
            'vouchers' => $vouchers
        ]);
    }
}
/*** End of Voucher Export Class ***/

/*** Voucher Controller ***/
public function export(Request $request, Excel $excel, VouchersExport $export)
{        
     return $excel->download($export, 'vouchers.xlsx');
}
/*** End of Voucher Controller ***/

最有用的评论

我通过实现WithTitle Class 得到了答案,只需返回我们想要的名称

use Maatwebsite\Excel\Concerns\WithTitle;
...

class VouchersExport implements FromView, WithTitle {
    ...
    public function title(): string
    {
        return 'Vouchers';
    }
}

所有2条评论

我通过实现WithTitle Class 得到了答案,只需返回我们想要的名称

use Maatwebsite\Excel\Concerns\WithTitle;
...

class VouchersExport implements FromView, WithTitle {
    ...
    public function title(): string
    {
        return 'Vouchers';
    }
}

@praditha正是我所需要的。

谢谢你。

此页面是否有帮助?
0 / 5 - 0 等级