์ผ๋ถ/๋ชจ๋ ์ํธ๊ฐ FromView์ธ ๊ฒฝ์ฐ ์ฌ๋ฌ ์ํธ๊ฐ ์๋ํ์ง ์์
`
ํด๋์ค FormatReportExport๋ WithMultipleSheets, Responsable์ ๊ตฌํํฉ๋๋ค.
{
๋ด๋ณด๋ด๊ธฐ ๊ฐ๋ฅ ์ฌ์ฉ;
protected $reports;
protected $summary;
public function __construct($summary, $reports)
{
$this->summary = $summary;
$this->reports = $reports;
}
public function sheets(): array
{
$sheets = [];
$sheets[] = new ReportSummaryExport($this->summary);
$sheets[] = new ReportExport($this->reports);
return $sheets;
}
}
`
`
ReportSummaryExport ํด๋์ค๋ FromCollection, WithTitle์ ๊ตฌํํฉ๋๋ค.
{
๋ณดํธ๋ $summary;
public function __construct($summary)
{
$this->summary = $summary;
}
public function collection()
{
return User::get();
}
/**
* <strong i="34">@return</strong> string
*/
public function title(): string
{
return 'Summary';
}
}`
`ํด๋์ค ReportExport๋ FromView, WithTitle์ ๊ตฌํํฉ๋๋ค.
{
๋ณดํธ๋ $reports;
public function __construct($reports)
{
$this->reports = $reports;
}
public function view(): View
{
return view('export.report.list', [
'title' => $this->title(),
'reports' => $this->reports
]);
}
/**
* <strong i="41">@return</strong> string
*/
public function title(): string
{
return 'Checklists';
}
}`
๋ชฉ๋ก.๋ธ๋ ์ด๋.php
`@extens('layouts.export', ['title' => $title])
@์น์ ('์ฝํ ์ธ ')
์์ฑ ์ผ์ |
{{ $report['created_at'] }} |
@endsection`
์์๋๋ ๋์:
๋ณด๊ธฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ ์ฌ๋ฌ ์ํธ๊ฐ ์๋ Excel ํ์ผ์ ๋๋ค.
์ค์ ํ๋:
ํฐ์ผ์ ์ ์ถํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฆฌ์์ค๊ฐ ํ๋ณด๋๋ ์ฆ์ ์ด๋ฅผ ์ ํํ๊ฒ ์ต๋๋ค(์ง์ ์ง์นจ(https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/support)์ ๋ช ์๋ ๋๋ก).
์๋ง๋ #1590์ ์ํด ํด๊ฒฐ๋ ๊ฒ์ ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
https://github.com/Maatwebsite/Laravel-Excel/releases/tag/3.0.2