Excel
Laravel-Excel
- github
- 根据已有模板,修改数据再导出
参考public function registerEvents(): array { return [ BeforeWriting::class => function (BeforeWriting $event) { $templateFile = new LocalTemporaryFile(storage_path('app/public/files/your_file.xlsx')); $event->writer->reopen($templateFile, Excel::XLSX); $event->writer->getSheetByIndex(0); $this->calledByEvent = true; // set the flag $event->writer->getSheetByIndex(0)->export($event->getConcernable()); // call the export on the first sheet return $event->getWriter()->getSheetByIndex(0); }, ]; }