123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Exports\Sheets;
- use App\Models\Fpdx\FormAnswerModel;
- use Maatwebsite\Excel\Concerns\FromQuery;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- use Maatwebsite\Excel\Concerns\WithMapping;
- use Maatwebsite\Excel\Concerns\WithTitle;
- use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
- class FormAnswerSheet implements FromQuery, WithTitle, WithMapping, WithHeadings
- {
- private $question;
- public function __construct($question)
- {
- $this->question = $question;
- }
- public function headings(): array
- {
- return [
- '#',
- 'User',
- 'Type',
- 'Answer',
- 'Date'
- ];
- }
- public function map($answer): array
- {
- return [
- '#',
- $answer->uid,
- $answer->type,
- $answer->answer,
- $answer->created_at,
- ];
- }
- public function query()
- {
- return FormAnswerModel::query()->where('question_id', $this->question->id);
- }
- /**
- * @return string
- */
- public function title(): string
- {
- return sprintf('第%s题', $this->question->sort);
- }
- public function columnFormats(): array
- {
- return [
- 'E' => NumberFormat::FORMAT_DATE_DDMMYYYY,
- ];
- }
- }
|