public function consolidated($id) { $data = array(); $excelSheets = array(); # report $report = Reports::getReportById($id); $data['report'] = $report; # get all files under this report $reportFiles = ReportFile::getReportFilesById($report->report_id); # get all version and sheets under this report for ($i = 0; $i < count($reportFiles); $i++) { // get current version $currentFileVersion = ReportFileVersion::getCurrentVersion($reportFiles[$i]->file_id); $reportFiles[$i]->currentFileVersion = $currentFileVersion; // get sheets $reportSheets = ReportFileSheets::getSheetsByVersionId($currentFileVersion->version_id); $reportFiles[$i]->reportSheets = $reportSheets; foreach ($reportSheets as $currentSheet) { $excelSheets[] = json_decode($currentSheet->data_table); } } $data['report_files'] = $reportFiles; Excel::create('Filename', function ($excel) use($excelSheets) { $excel->sheet('Sheetname', function ($sheet) use($excelSheets) { $sheet->fromArray($excelSheets); }); })->export('xls'); }
public function download($id = 0) { $currentReport = ConsolidatedReports::getById($id); $version = ConsolidatedReportsVersion::getById($id); # get table headers $originalReport = Reports::getReportById($currentReport->report_id); $reportFiles = ReportFile::getReportFilesById($originalReport->report_id); $reportColumns = array(); if (isset($reportFiles[0])) { $currentOriginalFile = $reportFiles[0]; $currentFileVersion = ReportFileVersion::getCurrentVersion($currentOriginalFile->file_id); // get sheets $reportColumns = ReportFileSheets::getFirstSheetByVersionId($currentFileVersion->version_id); $reportColumns = json_decode($reportColumns); $reportColumns = json_decode($reportColumns->data_table_columns); } # get table data $dataTable = json_decode($version->table_data); $report = ExcelExporter::formatFileArrays($dataTable); # combine headers and data $finalDataTable = array_merge($reportColumns, $report); # file name here $filename = "{$originalReport->incident_name} - Incident Number {$originalReport->incident_number}"; ExcelExporter::exportFileTest($finalDataTable, $filename); //$reformattedReport = }