Laravel-excel: ์ผ๋ถ€/๋ชจ๋“  ์‹œํŠธ๊ฐ€ FromView๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ ์—ฌ๋Ÿฌ ์‹œํŠธ๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š์Œ

์— ๋งŒ๋“  2018๋…„ 03์›” 26์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: Maatwebsite/Laravel-Excel

์ „์ œ ์กฐ๊ฑด

  • [ ] ์ฝ”๋“œ ์™ธ๋ถ€์—์„œ ๋™์ž‘์„ ์žฌํ˜„ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋Š” Laravel Excel๋กœ ๊ฒฉ๋ฆฌ๋ฉ๋‹ˆ๋‹ค.
  • [X] ๋ฌธ์ œ๊ฐ€ ์•„์ง ์ œ์ถœ๋˜์ง€ ์•Š์•˜๋Š”์ง€ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.
  • [X] ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” PR์ด ์ œ์ถœ๋˜์ง€ ์•Š์•˜๋Š”์ง€ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.

๋ฒ„์ „

  • PHP ๋ฒ„์ „: 7.2
  • ๋ผ๋ผ๋ฒจ ๋ฒ„์ „: 5.5
  • ํŒจํ‚ค์ง€ ๋ฒ„์ „: 3.0.1

์„ค๋ช…

์ผ๋ถ€/๋ชจ๋“  ์‹œํŠธ๊ฐ€ FromView์ธ ๊ฒฝ์šฐ ์—ฌ๋Ÿฌ ์‹œํŠธ๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š์Œ

  • FromView๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ชจ๋“  ์‹œํŠธ(์ž‘๋™ํ•˜์ง€ ์•Š์Œ)
  • 1 ์‹œํŠธ FromView ๋ฐ ๋‹ค๋ฅธ FromCollection ๊ตฌํ˜„(์ž‘๋™ํ•˜์ง€ ์•Š์Œ)
  • 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])

@์„น์…˜('์ฝ˜ํ…์ธ ')

@foreach($reports๋กœ $reports)@endforeach
์ƒ์„ฑ ์ผ์ž
{{ $report['created_at'] }}

@endsection`

์˜ˆ์ƒ๋˜๋Š” ๋™์ž‘:

๋ณด๊ธฐ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋Š” ์—ฌ๋Ÿฌ ์‹œํŠธ๊ฐ€ ์žˆ๋Š” Excel ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.

์‹ค์ œ ํ–‰๋™:

image

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๋ชจ๋“  3 ๋Œ“๊ธ€

ํ‹ฐ์ผ“์„ ์ œ์ถœํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฆฌ์†Œ์Šค๊ฐ€ ํ™•๋ณด๋˜๋Š” ์ฆ‰์‹œ ์ด๋ฅผ ์„ ํƒํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค(์ง€์› ์ง€์นจ(https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/support)์— ๋ช…์‹œ๋œ ๋Œ€๋กœ).

์•„๋งˆ๋„ #1590์— ์˜ํ•ด ํ•ด๊ฒฐ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰