setActiveSheetIndex(0); $worksheet = $spreadsheet->getActiveSheet(); $line = 0; $column = 1; //headers foreach ($data[0] as $header_col) { $worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($header_col))); $column++; } $line++; $cant_students = count($data[1]); for ($i = 0; $i < $cant_students; $i++) { $column = 0; foreach ($data[1][$i] as $col_name) { $worksheet->SetCellValueByColumnAndRow( $line, $column, html_entity_decode(strip_tags($col_name)) ); $column++; } $line++; } $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename); $writer = new PHPExcel_Writer_Excel2007($spreadsheet); $writer->save($file); DocumentManager::file_send_for_download($file, true, $filename); exit; } /** * Exports the complete report as a DOCX file * @param array $data The table data * @return bool */ public function exportCompleteReportDOC($data) { $filename = 'gradebook_results_'.api_get_local_time().'.docx'; $doc = new \PhpOffice\PhpWord\PhpWord(); $section = $doc->addSection(['orientation' => 'landscape']); $table = $section->addTable(); $table->addRow(); for ($i = 0; $i < count($data[0]); $i++) { $table->addCell(1750)->addText(strip_tags($data[0][$i])); } foreach ($data[1] as $dataLine) { $table->addRow(); for ($i = 0; $i < count($dataLine); $i++) { $table->addCell(1750)->addText(strip_tags($dataLine[$i])); } } $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename); $doc->save($file, 'Word2007'); DocumentManager::file_send_for_download($file, true, $filename); return true; } }