tieneAcceso()){ echo "No tienes permiso de ver esta página. Revisa que tu sesión siga activa."; exit(); } unset($objValida); //-------- // // Create new Spreadsheet object $spreadsheet = new Spreadsheet(); // Set document properties $spreadsheet->getProperties()->setCreator('Ingeniería La Salle') ->setLastModifiedBy('Ingeniería La Salle') ->setTitle('Estado de Alumnos') ->setDescription('Estado actual de alumnos.'); $headerStyle = new Style(); $headerStyle->applyFromArray( [ 'fill' => [ 'fillType' => Fill::FILL_SOLID, 'color' => ['argb' => 'FF001d68'], ], 'borders' => [ 'bottom' => ['borderStyle' => Border::BORDER_THIN], 'right' => ['borderStyle' => Border::BORDER_MEDIUM], ], 'font' => [ 'bold' => true, 'color' => ['argb' => 'FFFFFFFF'], ] ] ); //-------- $stmt = $pdo->prepare('Select * from "Alumno_view" where "Nivel_id"=:nivel AND "EstadoAlumno_id"=1');//sólo activos $stmt->bindParam(":nivel", $_SESSION["nivel_id"]); if(!$stmt->execute()){ echo "Ocurrió un error al cargar los alumnos."; //print_r($stmt->errorInfo()); exit(); } $alumno_rs = $stmt->fetchAll(); $stmt->closeCursor(); $spreadsheet->setActiveSheetIndex(0)->setTitle('Alumnos '); $row = 1; $col = 1; $spreadsheet->getActiveSheet() ->setCellValueByColumnAndRow($col++, $row, "Estado") ->setCellValueByColumnAndRow($col++, $row, "Subestado") ->setCellValueByColumnAndRow($col++, $row, "Clave") ->setCellValueByColumnAndRow($col++, $row, "Apellidos") ->setCellValueByColumnAndRow($col++, $row, "Nombre") ->setCellValueByColumnAndRow($col++, $row, "Generación") ->setCellValueByColumnAndRow($col++, $row, "CURP") ->setCellValueByColumnAndRow($col++, $row, "Carrera") ->setCellValueByColumnAndRow($col++, $row, "Plan"); $colMax = $col; $colLetter = numberToLetter($colMax-1); $spreadsheet->getActiveSheet()->duplicateStyle($headerStyle, 'A1:'.$colLetter.'1'); $row = 2; $startRow = $row; foreach($alumno_rs as $alumno){ $col = 1; //$spreadsheet->setActiveSheetIndex($sheet) $spreadsheet->getActiveSheet() ->setCellValueByColumnAndRow($col++, $row, $alumno["EstadoAlumno_desc"]) ->setCellValueByColumnAndRow($col++, $row, $alumno["SubEstadoAlumno_desc"]) ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_claveULSA"]) ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_apellidos"]) ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_nombre"]) ->setCellValueByColumnAndRow($col++, $row, fechaMonthPicker($alumno["Alumno_generacion"])) ->setCellValueByColumnAndRow($col++, $row, $alumno["Usuario_curp"]) ->setCellValueByColumnAndRow($col++, $row, $alumno["Carrera_desc"]) ->setCellValueByColumnAndRow($col++, $row, $alumno["PlanEstudio_desc"]); $spreadsheet->getActiveSheet()->getStyle(numberToLetter(1).$row)->applyFromArray(['font' => [ 'color' => ['argb' => str_replace("#", "FF", $alumno["EstadoAlumno_color"])] ] ]); $spreadsheet->getActiveSheet()->getStyle(numberToLetter(3).$row)->getNumberFormat()->setFormatCode('000000'); $row++; } $row--; //Auto ajustar anchos for($col = 1; $col < $colMax; $col++) $spreadsheet->getActiveSheet()->getColumnDimension(numberToLetter($col))->setAutoSize(true); //--------- // Set active sheet index to the first sheet, so Excel opens this as the first sheet $spreadsheet->setActiveSheetIndex(0); // Redirect output to a client’s web browser (Xlsx) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="alumnos_periodo.xlsx"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output'); exit;