๋ฐ์ดํฐ๋ฅผ 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๋ฅผ ๊ตฌํํ์ฌ ๋ต์ ์ป์๊ณ ์ํ๋ ์ด๋ฆ์ ๋ฐํํ๋ฉด ๋ฉ๋๋ค.