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.
/** 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 ***/
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.
Most helpful comment
I've got my answer by implement
WithTitleClass and just return the name what we want