Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/03/2013, 07:48
Avatar de evolutionrgm
evolutionrgm
 
Fecha de Ingreso: mayo-2011
Mensajes: 108
Antigüedad: 13 años
Puntos: 5
Respuesta: Exportar tabla a excel

Hola estimado prueba esto y me dices

Código PHP:
Ver original
  1.     include("config.php");
  2. //agregue esta sentencia      
  3. echo "";
  4.     echo "<html>";
  5.     echo "<head>";
  6.     $db=mysql_pconnect($server,$db_user,$db_pass);
  7.     if (!$db) die("Error al conectar con la base de datos. Ponte en contacto con el programador");
  8.     mysql_select_db("$database");
  9.     $sql1="select * from clientes where clientes.ID>'3'";
  10.     $res1=mysql_query($sql1);
  11.     if (!$res1) echo "Ha ocurrido un error al recuperar los clientes";                
  12.     else
  13.         {
  14.          echo "<table align='center' border='1'>";
  15.          echo "<tr><td colspan='9' align='center'><b> Lista de Socios </b> </td></tr>";
  16.          echo "<tr><td><b>Nombre</td><td><b>Apellidos</td><td><b>Usuario</td><td><b>Teléfono</td><td><b>Dirección</td><td><b>Población</td><td><b>Email</td><td><b>Socio</td><td><b>Activado</td></b></tr>";                          
  17.                 while ($reg1=mysql_fetch_array($res1))
  18.                         {
  19.                         echo "<tr><td>$reg1[1]</td><td>$reg1[2]</td><td>$reg1[3]</td><td>$reg1[5]</td><td>$reg1[6]</td><td>$reg1[7]</td><td>$reg1[8]</td><td>$reg1[9]</td><td>$reg1[10]</td></tr>";
  20.                         }
  21.                  echo "</table>";
  22.                  echo "<a href='./listado.php'>Exportar</a>";
  23.                 }
  24.        
  25. echo "</body>         ";
  26. echo "</html>";  
  27.  
  28. $reporte = ob_get_clean();
  29. /********************************************
  30. Set the automatic downloadn section
  31. /********************************************/
  32.  
  33. header("Content-type: application/vnd.ms-excel");
  34. header("Content-Disposition: attachment; filename=consulta.xls");
  35. header("Pragma: no-cache");
  36. header("Expires: 0");  
  37.  
  38. echo $reporte;
  39.  
  40. }