123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace App\Admin\Exports;
- use Encore\Admin\Grid\Exporters\AbstractExporter;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Collection;
- use Maatwebsite\Excel\Concerns\Exportable;
- use Maatwebsite\Excel\Concerns\FromCollection;
- use Maatwebsite\Excel\Concerns\RegistersEventListeners;
- use Maatwebsite\Excel\Concerns\ShouldAutoSize;
- use Maatwebsite\Excel\Concerns\WithColumnFormatting;
- use Maatwebsite\Excel\Concerns\WithEvents;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- use Maatwebsite\Excel\Concerns\WithMapping;
- use Maatwebsite\Excel\Events\AfterSheet;
- use Maatwebsite\Excel\Events\BeforeSheet;
- use Maatwebsite\Excel\Events\BeforeWriting;
- use PhpOffice\PhpSpreadsheet\Shared\Font;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- abstract class RowExport extends AbstractExporter implements
- FromCollection,
- WithHeadings,
- ShouldAutoSize,
- WithColumnFormatting,
- WithMapping,
- WithEvents
- {
- use Exportable, RegistersEventListeners;
-
- private $customerData = null;
-
- public function getCustomerData()
- {
- return $this->customerData;
- }
-
- public function setCustomerData(Collection $customerData)
- {
- $this->customerData = $customerData;
- return $this;
- }
-
- public function collection()
- {
- return $this->getCustomerData()?:$this->getData(false);
- }
-
- public function export()
- {
- $this->download($this->getFilename())->send();
- exit;
- }
-
- abstract public function headings(): array ;
-
- abstract public function map($row): array ;
-
- abstract public function getFilename(): string ;
-
- abstract public function columnFormats(): array ;
- public static function beforeWriting(BeforeWriting $event)
- {
- Font::setAutoSizeMethod(Font::AUTOSIZE_METHOD_EXACT);
- Font::setTrueTypeFontPath(public_path('fonts/'));
- $event->getWriter()->getDelegate()->getDefaultStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
- $event->getWriter()->getDelegate()->getDefaultStyle()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
- }
- public static function beforeSheet(BeforeSheet $event)
- {
- }
- public static function afterSheet(AfterSheet $event)
- {
-
- }
- }
|