Laravel-excel: [Question] - How to change the default sheet name ?

Created on 26 Mar 2018  路  2Comments  路  Source: Maatwebsite/Laravel-Excel

Versions

  • PHP version: 7.1.9
  • Laravel version: 5.5
  • Package version: 3.0

Description

I cannot find how to change the sheet name in the document for exporting the data into excel file.
Instead of use Worksheet as a default sheet name, I want to change it based on what data I will provide.

Thanks for this excellent package.

My Code

/** 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
{    
    /**
     * @return 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 ***/

Most helpful comment

I've got my answer by implement WithTitle Class and just return the name what we want

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

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

All 2 comments

I've got my answer by implement WithTitle Class and just return the name what we want

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

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

@praditha era justo lo que necesitaba.

Muchas gracias.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gamevnlc picture gamevnlc  路  3Comments

matthewslouismarie picture matthewslouismarie  路  3Comments

muhghazaliakbar picture muhghazaliakbar  路  3Comments

alejandri picture alejandri  路  3Comments

dr3ads picture dr3ads  路  3Comments