| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Exports;
- use Maatwebsite\Excel\Concerns\WithMultipleSheets;
- class ItemSalaryFTMultipleSheetExport implements WithMultipleSheets
- {
- protected $monthsData;
- protected $projects;
- protected $company;
- /**
- * @param array $monthsData 格式需要包含该月特有的项目列表:
- * [
- * '2024年4月' => [
- * 'projects' => ['RD01', 'RD02'],
- * 'data' => [ [...] ]
- * ],
- * '2024年5月' => [
- * 'projects' => ['RD03'],
- * 'data' => [ [...] ]
- * ]
- * ]
- */
- public function __construct(array $monthsData,$company)
- {
- $this->monthsData = $monthsData;
- $this->company = $company;
- }
- public function sheets(): array
- {
- $sheets = [];
- foreach ($this->monthsData as $month => $item) {
- // 每次实例化 Sheet 时,传入该月特有的 projects 列表
- $sheets[] = new ItemSalaryFTSheetExport(
- $month,
- $item['data'],
- $item['projects'],
- $this->company
- );
- }
- return $sheets;
- }
- }
|