我找不到如何更改文档中的工作表名称以将数据导出到 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';
}
}
@praditha正是我所需要的。
谢谢你。
最有用的评论
我通过实现
WithTitle
Class 得到了答案,只需返回我们想要的名称