Ver Mensaje Individual
  #4 (permalink)  
Antiguo 26/10/2011, 07:30
Sirrohan
 
Fecha de Ingreso: julio-2010
Mensajes: 275
Antigüedad: 13 años, 10 meses
Puntos: 21
Respuesta: exportar php a excel

Código PHP:
Ver original
  1. $sql = "SELECT * FROM tabla";
  2. $consul=pg_query($sql);
  3.  
  4. $nombreXLS = date("d-m-Y_his");//se crea un nombre unico con la fecha y hora del reloj
  5.  
  6.     header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");  
  7.     header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");  
  8.     header ("Cache-Control: no-cache, must-revalidate");  
  9.     header ("Pragma: no-cache");  
  10.     header ("Content-type: application/vnd.ms-excel"); //cabecera para que el formato de salida se hecho por ms-excel
  11.     header ("Content-Disposition: attachment; filename=Archivo_".$nombreXLS.".xls");//Nombre del archivo Generado con el tiempo de reloj
  12.  
  13. echo '<table width="820" align="center" border=1 cellspacing=0 cellpadding=2 bordercolor="666633">
  14.        <tr class="Estilism">
  15.            <td width="126" bgcolor="#99CCFF"><div align="center">Nombre</div></td>
  16.            <td width="174" bgcolor="#99CCFF"><div align="center">&Aacute;rea</div></td>
  17.            <td width="118" bgcolor="#99CCFF"><div align="center">Tipo</div></td>
  18.            <td width="93" bgcolor="#99CCFF"><div align="center">Fecha</div></td>
  19.            <td width="130" bgcolor="#99CCFF"><div align="center">Direcci&oacute;n</div></td>
  20.            <td width="151" bgcolor="#99CCFF" align="center"><div align="center">Observaci&oacute;n</div></td>
  21.         </tr>';
  22. $con=pg_query($sql);
  23. if(pg_num_rows($con)<=0)
  24. {
  25.     ?>
  26. <script> alert("No hay nombres seleccionados"); </script>
  27.       <?
  28.     echo '<script languaje="Javascript">location.href="Index.html"</script>';
  29. }
  30. if (pg_num_rows( $con) >0)
  31.  
  32. while ($reg = pg_fetch_object($con))
  33. {
  34.     echo '<tr class="Estilo3">';
  35.     echo '<td bgcolor="#99FFFF"><div align="center">'.$reg->nombre.'</div></td>';
  36.     echo '<td bgcolor="#99FFFF"><div align="center">'.$reg->area.'</div></td>';
  37.     echo '<td bgcolor="#99FFFF"><div align="center">'.$reg->tipo.'</div></td>';
  38.     echo '<td bgcolor="#99FFFF"><div align="center">'.$reg->fecha.'</div></td>';
  39.     echo '<td bgcolor="#99FFFF"><div align="center">'.$reg->direccion.'</div></td>';
  40.     echo '<td bgcolor="#99FFFF"><div align="center">'.$reg->observacion.'</div></td>';
  41.     echo '</tr>';
  42.  
  43. }
  44.     echo '</table>';
  45.  
  46. ?>