ItemSalaryFTMultipleSheetExport.php 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Exports;
  3. use Maatwebsite\Excel\Concerns\WithMultipleSheets;
  4. class ItemSalaryFTMultipleSheetExport implements WithMultipleSheets
  5. {
  6. protected $monthsData;
  7. protected $projects;
  8. /**
  9. * @param array $monthsData 格式需要包含该月特有的项目列表:
  10. * [
  11. * '2024年4月' => [
  12. * 'projects' => ['RD01', 'RD02'],
  13. * 'data' => [ [...] ]
  14. * ],
  15. * '2024年5月' => [
  16. * 'projects' => ['RD03'],
  17. * 'data' => [ [...] ]
  18. * ]
  19. * ]
  20. */
  21. public function __construct(array $monthsData)
  22. {
  23. $this->monthsData = $monthsData;
  24. }
  25. public function sheets(): array
  26. {
  27. $sheets = [];
  28. foreach ($this->monthsData as $month => $item) {
  29. // 每次实例化 Sheet 时,传入该月特有的 projects 列表
  30. $sheets[] = new ItemSalaryFTSheetExport(
  31. $month,
  32. $item['data'],
  33. $item['projects']
  34. );
  35. }
  36. return $sheets;
  37. }
  38. }