tieneAcceso()){ echo "No tienes permiso de ver esta página. Revisa que tu sesión siga activa."; exit(); } unset($objValida); if(!isset($_POST["generacion"], $_POST["carrera"])){ echo "No se recibieron los datos necesarios."; exit(); } $filter_carrera = filter_input(INPUT_POST, "carrera", FILTER_SANITIZE_NUMBER_INT);//limpia texto //$filter_gen = fechaGuion(trim(filter_input(INPUT_POST, "generacion", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto $prefijo = (trim(filter_input(INPUT_POST, "prefijo", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto $query = "NULL, NULL, NULL, :carr, NULL, "; if(isset($_POST["estado"]) && $_POST["estado"]!=""){ $query .= ":edo, "; $filter_estado = filter_input(INPUT_POST, "estado", FILTER_SANITIZE_NUMBER_INT);//limpia texto }else{ $query .= "NULL, "; } $query .= "0, NULL"; $stmt = $pdo->prepare('Select * from fs_alumnobusca_carrera('.$query.') ORDER BY "Usuario_apellidos", "Usuario_nombre", "PlanEstudio_desc"'); $stmt->bindParam(":carr", $filter_carrera); //$stmt->bindParam(":gen", $filter_gen); if(isset($filter_estado)) $stmt->bindParam(":edo", $filter_estado); if(!$stmt->execute()){ $errorDesc = "Ocurrió un error al cargar los alumnos."; //print_r($stmt->errorInfo()); }else{ $alumnos_rs = $stmt->fetchAll(); } $stmt->closeCursor(); $stmt = null; //-------- // // Create new Spreadsheet object $spreadsheet = new Spreadsheet(); // Set document properties $spreadsheet->getProperties()->setCreator('Ingeniería La Salle') ->setLastModifiedBy('Ingeniería La Salle') ->setTitle('Alumnos por carrera') ->setDescription('Alumnos por carrera por generación.'); $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'], ] ] ); $titleStyle = new Style(); $titleStyle->applyFromArray( [ 'font' => [ 'bold' => true, 'size' => 14, ] ] ); //-------- $sheet = 0; $spreadsheet->setActiveSheetIndex($sheet)->setTitle('Alumnos '.$prefijo); $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow(1, 1, "Alumnos ".$prefijo); $spreadsheet->getActiveSheet()->mergeCells('A1:D1'); $spreadsheet->getActiveSheet()->duplicateStyle($titleStyle, 'A1:D1'); $row = 3; $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, "Correo") ->setCellValueByColumnAndRow($col++, $row, "Carrera") ->setCellValueByColumnAndRow($col++, $row, "Plan"); $colMax = $col; $colLetter = numberToLetter($colMax-1); $spreadsheet->getActiveSheet()->duplicateStyle($headerStyle, 'A'.$row.':'.$colLetter.$row); $row++; $startRow = $row; foreach($alumnos_rs as $alumno){ $col = 1; //$spreadsheet->setActiveSheetIndex($sheet) $correo = ""; $stmt = $pdo->prepare('SELECT "Contacto_valor" from fs_contacto(:id, 3, NULL) WHERE "Contacto_valor" ILIKE \'%\' || \'lasallistas.org.mx\''); $stmt->bindParam(":id", $alumno["Usuario_id"]); if($stmt->execute()){ $contacto_rs = $stmt->fetch(); $correo = $contacto_rs["Contacto_valor"]; } $stmt->closeCursor(); if($correo == ""){ $stmt = $pdo->prepare('SELECT "Contacto_valor" from fs_contacto(:id, 3, NULL) WHERE "Contacto_valor" NOT ILIKE \'%\' || \'lasallistas.org.mx\''); $stmt->bindParam(":id", $alumno["Usuario_id"]); if($stmt->execute()){ $contacto_rs = $stmt->fetch(); $correo = $contacto_rs["Contacto_valor"]; } $stmt->closeCursor(); } $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, $correo) ->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'.$prefijo.'_'.str_replace(array(',', ' '), array('',''), fechaMonthPicker($filter_gen)).'.xlsx"'); header('Content-Disposition: attachment;filename="alumnos'.$prefijo.'.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;