Ver Mensaje Individual
  #6 (permalink)  
Antiguo 24/01/2013, 09:15
Avatar de andres_15_
andres_15_
 
Fecha de Ingreso: septiembre-2008
Ubicación: Cali
Mensajes: 232
Antigüedad: 15 años, 7 meses
Puntos: 7
Respuesta: Exportar a Excel tabla mysql

Cita:
Iniciado por facundojr07 Ver Mensaje
Código PHP:
<?php
error_reporting
(E_ERROR);
require(
"conexion.php");
require(
"funciones.php");
header("Content-type: application/vnd.ms-excel" ) ; //Exporar a Excel
header("Content-Disposition: attachment; filename=estadisticas.xls" ) ; //Exporar a Excel

//.sqlValue($criterio1."%", "text")

    
$query "SELECT * FROM bd_rtdmf WHERE ID_N IN ('000')";
    
$queEmp mysql_query($query$conexion);
    
$campos mysql_num_fields($query) ; 

$i=0//Exporar a Excel
echo "<table><tr>"
while(
$i<$campos){ 
echo 
"<td>"mysql_field_name ($query$i) ; 
echo 
"</td>"
$i++; 

echo 
"</tr>"
while(
$row=mysql_fetch_array($query)){ 
echo 
"<tr>"
for(
$j=0$j<$campos$j++) { 
echo 
"<td>".$row[$j]."</td>"

echo 
"</tr>"

echo 
"</table>"

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Red Banda Ancha Fija</title>

<link href="styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="Silverlight Binaries/Visifire.js"></script>

</head>
<body>
<table width="100%" border="0">
  <tr>
    <td>
          <div align="center"><?php
    
include('menu-rtdmf4.php');
?>
      </div>
    </td>
  </tr>
  <tr>
    <td><p><span class="TITULO">000</span></p>
      <table width="100%" border="1" cellpadding="0" cellspacing="0">
      <tr>
        <th><div align="center">Mes</div></th>
        <th><div align="center">Trafico</div></th>
        <th><div align="center">Intentos</div></th>
        <th><div align="center">Tomas</div></th>
        <th><div align="center">Contestadas</div></th>
        <th><div align="center">Desborde</div></th>
        <th><div align="center">% TTR </div></th>
        <th><div align="center">% Desborde </div></th>
      </tr>
      <?php while ($rsEmp mysql_fetch_assoc($queEmp)) { ?>
      <tr>
        <td><div align="center"><?php echo $rsEmp['Nombre_mes']; ?></div></td>
        <td><div align="center"><?php echo $rsEmp['Trafico']; ?></div></td>
        <td><div align="center"><?php echo $rsEmp['Intentos']; ?></div></td>
        <td><div align="center"><?php echo $rsEmp['Tomas']; ?></div></td>
        <td><div align="center"><?php echo $rsEmp['Contestadas']; ?></div></td>
        <td><div align="center"><?php echo $rsEmp['Desborde']; ?></div></td>
        <td><div align="center"><?php echo $rsEmp['TTR']; ?></div></td>
        <td><div align="center"><?php echo $rsEmp['Desborde1']; ?></div></td>
      </tr>
      <?php ?>
    </table></td>
  </tr>
</table>
<table width="100%" border="0">
  <tr>
    <td width="50%" valign="top"><div align="center">
      <iframe id="grafico1" name="grafico1" src="pag-rtdmf-000-grafico1.php" frameborder="0" framespacing="0" scrolling="No" border="0" width="525"; height="325"> Necesita que su navegador soporte iframe para ver el gr&aacute;fico. Muchas gracias. </iframe>
    </div></td>
    <td width="50%"><div align="center">
      <iframe id="grafico2" name="grafico2" src="pag-rtdmf-000-grafico2.php" frameborder="0" framespacing="0" scrolling="No" border="0" width="525"; height="325"> Necesita que su navegador soporte iframe para ver el gr&aacute;fico. Muchas gracias. </iframe>
    </div></td>
  </tr>
</table>
</body>
</html>
Esa es la pagína. Donde muestra una tabla desde una base de datos. Lo que estoy queriendo hacer es que mediante un link me exporte esa tabla de mysql a excel. Gracias por tus respuestas.
Podrias hacer esto (antes que todo Quitar Las etiquetas que te crean el archivo excell, para que solo te muestre la tabla) :

[PHP][QUOTE=facundojr07;4354680]
Código PHP:
<?php
/*error_reporting(E_ERROR);
require("conexion.php");
require("funciones.php");
header("Content-type: application/vnd.ms-excel" ) ; //Exporar a Excel
header("Content-Disposition: attachment; filename=estadisticas.xls" ) ; //Exporar a Excel*/ 
Esto es lo que deberias quitarle

//.sqlValue($criterio1."%", "text")

    
$query "SELECT * FROM bd_rtdmf WHERE ID_N IN ('000')";
    
$queEmp mysql_query($query$conexion);
    
$campos mysql_num_fields($query) ; 

$i=0//Exporar a Excel
echo "<table><tr>"
while(
$i<$campos){ 
echo 
"<td>"mysql_field_name ($query$i) ; 
echo 
"</td>"
$i++; 

echo 
"</tr>"
while(
$row=mysql_fetch_array($query)){ 
echo 
"<tr>"
for(
$j=0$j<$campos$j++) { 
echo 
"<td>".$row[$j]."</td>"

echo 
"</tr>"

echo 
"</table>"

//al final de la consulta imprimes esto

echo "
<form action="" method="
POST"> 
            <input type='reset' value='Generar Archivo Excell'> 
</form>
            "
;

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Red Banda Ancha Fija</title>

<link href="styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="Silverlight Binaries/Visifire.js"></script>

</head>
<body>
<table width="100%" border="0">
  <tr>
    <td>
          <div align="center"><?php
    
include('menu-rtdmf4.php');


 

?>
Creo que te seriviria, pruebale y cuentame como te fue