metaRows()), ]; foreach ($this->payload->sections as $section) { $sheets[] = new ArraySheetExport($this->sheetTitle($section->title), $this->sectionRows($section)); } return $sheets; } private function metaRows(): array { $rows = [['Показатель', 'Значение']]; foreach ($this->payload->meta as $label => $value) { $rows[] = [$label, $value]; } return $rows; } private function sectionRows(ReportSection $section): array { $rows = [array_values($section->columns)]; if (empty($section->rows)) { $rows[] = ['Нет данных за выбранный период']; } foreach ($section->rows as $row) { $line = []; foreach (array_keys($section->columns) as $key) { $line[] = $row[$key] ?? ''; } $rows[] = $line; } return $rows; } private function sheetTitle(string $title): string { // Excel ограничивает название листа 31 символом и запрещает символы \/?*[]: return mb_substr(preg_replace('/[\\\\\/\?\*\[\]:]/', ' ', $title), 0, 31); } }