Codigo para armar planillas excel
Versión 3 (Guillermo Zdanowicz, 13/02/2013 11:41)
| 1 | 1 | Guillermo Zdanowicz | h1. Codigo para armar planillas excel |
|---|---|---|---|
| 2 | 3 | Guillermo Zdanowicz | h3. |
| 3 | 2 | Guillermo Zdanowicz | <pre> |
| 4 | 1 | Guillermo Zdanowicz | |
| 5 | 1 | Guillermo Zdanowicz | public function executeMostraralumnos() |
| 6 | 1 | Guillermo Zdanowicz | { |
| 7 | 1 | Guillermo Zdanowicz | $idanio = $this->getRequestParameter('anio'); |
| 8 | 1 | Guillermo Zdanowicz | |
| 9 | 1 | Guillermo Zdanowicz | |
| 10 | 1 | Guillermo Zdanowicz | // Obtener nuevos inscriptos por anio |
| 11 | 1 | Guillermo Zdanowicz | $resultado = AlumnosPeer::getAlumnosActivos($idanio); |
| 12 | 1 | Guillermo Zdanowicz | |
| 13 | 1 | Guillermo Zdanowicz | |
| 14 | 1 | Guillermo Zdanowicz | //Creamos el archivo temporal de exportación |
| 15 | 1 | Guillermo Zdanowicz | $file = 'al'.$idanio.'.csv'; |
| 16 | 1 | Guillermo Zdanowicz | $fh = fopen($file,"w+") or die ("unable to open file"); |
| 17 | 1 | Guillermo Zdanowicz | |
| 18 | 1 | Guillermo Zdanowicz | $titulo = "Nombre, Apellido, NroDoc, Carrera, FechaIngreso,"."\n"; |
| 19 | 1 | Guillermo Zdanowicz | fwrite($fh,$titulo); |
| 20 | 1 | Guillermo Zdanowicz | |
| 21 | 1 | Guillermo Zdanowicz | foreach($resultado as $datos){ |
| 22 | 1 | Guillermo Zdanowicz | //Cabecera - Cambienla por sus necesidades |
| 23 | 1 | Guillermo Zdanowicz | $row = $datos[0].",".$datos[1].",".$datos[2].",".$datos[3].",".$datos[4].","."\n"; |
| 24 | 1 | Guillermo Zdanowicz | fwrite($fh,$row); |
| 25 | 1 | Guillermo Zdanowicz | } |
| 26 | 1 | Guillermo Zdanowicz | |
| 27 | 1 | Guillermo Zdanowicz | // Close file |
| 28 | 1 | Guillermo Zdanowicz | fclose($fh); |
| 29 | 1 | Guillermo Zdanowicz | |
| 30 | 1 | Guillermo Zdanowicz | header("Content-Type: application/vnd.ms-excel"); |
| 31 | 1 | Guillermo Zdanowicz | header("Content-Type: application/force-download"); |
| 32 | 1 | Guillermo Zdanowicz | header("Content-Transfer-Encoding: binary"); |
| 33 | 1 | Guillermo Zdanowicz | header("Content-Disposition: attachment;filename=".$file ); |
| 34 | 1 | Guillermo Zdanowicz | header("Content-Length: ".filesize($file)); |
| 35 | 1 | Guillermo Zdanowicz | header("Pragma: no-cache"); |
| 36 | 1 | Guillermo Zdanowicz | header("Expires: 0"); |
| 37 | 1 | Guillermo Zdanowicz | readfile($file); |
| 38 | 1 | Guillermo Zdanowicz | |
| 39 | 1 | Guillermo Zdanowicz | return sfView::NONE; |
| 40 | 2 | Guillermo Zdanowicz | } |
| 41 | 2 | Guillermo Zdanowicz | </pre> |