customerData; } /** * @param Collection $customerData * @return $this */ public function setCustomerData(Collection $customerData) { $this->customerData = $customerData; return $this; } /** * @return Collection */ public function collection() { return $this->getCustomerData()?:$this->getData(false); } /** * {@inheritdoc} */ public function export() { $this->download($this->getFilename())->send(); exit; } /** * 设置标题,返回标题数组 * @return array */ abstract public function headings(): array ; /** * 处理行数据 * @param Model $row * @return array */ abstract public function map($row): array ; /** * 设置文件名 * @return string */ abstract public function getFilename(): string ; /** * 格式化指定列. * 只有在需要的时候设置,例如在身份证不要显示科学计数时设定列格式:['A'=>NumberFormat::FORMAT_NUMBER] * @return array */ 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) { //$event->getSheet()->getDelegate()->getColumnDimension('A')->setWidth(50); } }