Codigo para armar planillas excel

Versión 2 (Guillermo Zdanowicz, 27/08/2012 19:10) → Versión 3/4 (Guillermo Zdanowicz, 13/02/2013 11:41)

h1. Codigo para armar planillas excel
h3.
<pre>

public function executeMostraralumnos()
{
$idanio = $this->getRequestParameter('anio');


// Obtener nuevos inscriptos por anio
$resultado = AlumnosPeer::getAlumnosActivos($idanio);


//Creamos el archivo temporal de exportación
$file = 'al'.$idanio.'.csv';
$fh = fopen($file,"w+") or die ("unable to open file");

$titulo = "Nombre, Apellido, NroDoc, Carrera, FechaIngreso,"."\n";
fwrite($fh,$titulo);

foreach($resultado as $datos){
//Cabecera - Cambienla por sus necesidades
$row = $datos[0].",".$datos[1].",".$datos[2].",".$datos[3].",".$datos[4].","."\n";
fwrite($fh,$row);
}

// Close file
fclose($fh);

header("Content-Type: application/vnd.ms-excel");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment;filename=".$file );
header("Content-Length: ".filesize($file));
header("Pragma: no-cache");
header("Expires: 0");
readfile($file);

return sfView::NONE;
}
</pre>
Redmine Appliance - Powered by TurnKey Linux