MultiSheetExport.php 788 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App\Exports;
  3. use Maatwebsite\Excel\Concerns\WithMultipleSheets;
  4. class MultiSheetExport implements WithMultipleSheets
  5. {
  6. protected $data;
  7. protected $type;
  8. protected $column;
  9. protected $timeRow;
  10. public function __construct(array $data, int $type = 1, array $column, array $timeRow)
  11. {
  12. $this->data = $data;
  13. $this->type = $type;
  14. $this->column = $column;
  15. $this->timeRow = $timeRow;
  16. }
  17. public function sheets(): array
  18. {
  19. $sheets = [];
  20. foreach ($this->data as $sheetName => $sheetData) {
  21. // 将 type 传给 SingleSheetExport
  22. $sheets[] = new SingleSheetExport($sheetData, $sheetName, $this->type, $this->column, $this->timeRow);
  23. }
  24. return $sheets;
  25. }
  26. }