You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ***/
The text was updated successfully, but these errors were encountered:
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';
}
}
You should take into account that this works perfectly, as long as your html file doesn't have a <title> attribute on the header. This overrides the WithTitle concern. You should remove the <title> html attribute.
Versions
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
The text was updated successfully, but these errors were encountered: