Foros del Web » Programando para Internet » PHP »

exportar tabla mysql a excel

Estas en el tema de exportar tabla mysql a excel en el foro de PHP en Foros del Web. Lo que estoy intentando hacer, es "simplemente" eso: exportar una tabla de mysql a un archivo excel, mediante php... pero no soy capaz. ¿Alguien sabe ...
  #1 (permalink)  
Antiguo 24/06/2005, 04:42
 
Fecha de Ingreso: marzo-2004
Ubicación: Extremadura
Mensajes: 206
Antigüedad: 20 años, 1 mes
Puntos: 0
exportar tabla mysql a excel

Lo que estoy intentando hacer, es "simplemente" eso: exportar una tabla de mysql a un archivo excel, mediante php... pero no soy capaz. ¿Alguien sabe cómo hacerlo?
  #2 (permalink)  
Antiguo 24/06/2005, 06:45
 
Fecha de Ingreso: febrero-2004
Mensajes: 1.987
Antigüedad: 20 años, 2 meses
Puntos: 22
Exporta tus datos de tal forma que sea una TABLA html.

Arriba colocas los titulos, debajo de ellos los valores.

No exportes eso como .HTM sino como .XLS y Excel lo abrira como tál.
  #3 (permalink)  
Antiguo 24/06/2005, 06:52
Avatar de carlosechelon  
Fecha de Ingreso: octubre-2003
Ubicación: campana.baires
Mensajes: 71
Antigüedad: 20 años, 5 meses
Puntos: 0
probá esto......suerte!

Código PHP:
<?php
    header
("Pragma: no-cache");
    include (
"functions/conexion.php"); // inclui la coneccion .... o generala aqui adentro.....
?>
<HTML>
<body>

Código PHP:
<?php
                     $sql   
"SELECT * FROM tabla1 ";
                     
$sql  .= " WHERE campo2 = '$id2' ";
                     
$sql  .= " ORDER BY campo3";
                    
$result mysql_query($sql);
                    
                           
$shtml .= "<table width='718' cellpadding='1' cellspacing='1'>";  
                     
$shtml .= "<tr>";
                     
$shtml .=     "<td colspan=9 height='80'>";
                    
$shtml .= "Titulo: "// aca pone el titulo
                     
$shtml .=     "</td>";
                     
$shtml .= "</tr>"
                          
                     
$shtml .= "<tr>";
                     
$shtml .= "<td width='100'  height='18' style='padding: 2' bgcolor='#C0C0C0' align='left'><font size='2' face='Arial'><b>1</b></div></td>";
                     
$shtml .= "<td width='100'     height='18' style='padding: 2' bgcolor='#C0C0C0' align='left'><font size='2' face='Arial'><b>2</b></td>";
                     
$shtml .= "<td width='100'     height='18' style='padding: 2' bgcolor='#C0C0C0' align='left'><font size='2' face='Arial'><b>3</b></td>";
                     
$shtml .= "<td width='100'  height='18' style='padding: 2' bgcolor='#C0C0C0' align='left'><font size='2' face='Arial'><b>4</b></td>";
                     
$shtml .= "<td width='100'  height='18' style='padding: 2' bgcolor='#C0C0C0' align='left'><font size='2' face='Arial'><b>5</b></td>";
                     
$shtml .= "<td width='100'     height='18' style='padding: 2' bgcolor='#C0C0C0' align='left'><font size='2' face='Arial'><b>6</b></td>";
                     
$shtml .= "<td width='100'     height='18' style='padding: 2' bgcolor='#C0C0C0' align='left'><font size='2' face='Arial'><b>7</b></td>";
                     
$shtml .= "<td width='100'     height='18' style='padding: 2' bgcolor='#C0C0C0' align='left'><font size='2' face='Arial'><b>8</b></td>";
                     
$shtml .= "</tr>";
          
                     while (
$row mysql_fetch_row($result)) {  
                     
$shtml .= "<tr>"
                     
$shtml .= "<td width='100' bgcolor='#E1E1E1' style='padding: 2' height='25' align='left'><font size='2' face='Arial'>$row[1]    </td>";
                     
$shtml .= "<td width='100' bgcolor='#E1E1E1' style='padding: 2' height='25' align='left'><font size='2' face='Arial'>$row[0]     </td>";
                     
$shtml .= "<td width='100' bgcolor='#E1E1E1' style='padding: 2' height='25' align='left'><font size='2' face='Arial'>$row[2]     </td>";
                     
$shtml .= "<td width='100' bgcolor='#E1E1E1' style='padding: 2' height='25' align='left'><font size='2' face='Arial'>$row[3]     </td>";
                     
                     
                            
                     
$shtml .= "</td>";
                     
$shtml .= "<td width='100' bgcolor='#E1E1E1' style='padding: 2' height='25' align='left'><font size='2' face='Arial'>$row[5]      </td>";
                     
$shtml .= "<td width='100' bgcolor='#E1E1E1' style='padding: 2' height='25' align='left'><font size='2' face='Arial'>$row[6]      </td>";
                     
$shtml .= "<td width='100' bgcolor='#E1E1E1' style='padding: 2' height='25' align='left'><font size='2' face='Arial'>$row[7]     </td>";
                     
$shtml .= "<td width='250' bgcolor='#E1E1E1' style='padding: 2' height='25' align='left'><font size='2' face='Arial'>$row[8]      </td>";
                        
$shtml .= "</tr>";
                        
$shtml .= "<tr>";
                        
$shtml .= "<td  height='1' bgcolor='#cccccc'></td>";
                        
$shtml .= "<td  height='1' bgcolor='#cccccc'></td>";
                        
$shtml .= "<td  height='1' bgcolor='#cccccc'></td>";
                        
$shtml .= "<td  height='1' bgcolor='#cccccc'></td>";
                        
$shtml .= "<td  height='1' bgcolor='#cccccc'></td>";
                        
$shtml .= "<td  height='1' bgcolor='#cccccc'></td>";
                        
$shtml .= "<td  height='1' bgcolor='#cccccc'></td>";
                        
$shtml .= "<td  height='1' bgcolor='#cccccc'></td>";
                        
$shtml .= "<td  height='1' bgcolor='#cccccc'></td>";
                        
$shtml .= "</tr>"
                    }       
                    
$shtml .= "</table>";
                    
$scarpeta="excel/"
                            
//debe tener permisos 775 por lo menos
                            
$sfile=$scarpeta."".strftime("%H_%M_%S").".xls"//ruta del archivo a generara
                            
$fp=fopen($sfile,"w");
                            
fwrite($fp,$shtml);
                            
fclose($fp);
                            echo 
"<script language='javascript'>";
                            echo 
"location.href= '$sfile'";
                            echo 
"</script>";    
                    
                    
                
?>
</body>
</html>
  #4 (permalink)  
Antiguo 24/06/2005, 07:32
 
Fecha de Ingreso: marzo-2004
Ubicación: Extremadura
Mensajes: 206
Antigüedad: 20 años, 1 mes
Puntos: 0
muchas gracias a ambos. voy a probar
  #5 (permalink)  
Antiguo 28/02/2006, 11:40
 
Fecha de Ingreso: febrero-2006
Mensajes: 1
Antigüedad: 18 años, 1 mes
Puntos: 0
y como te fue con eso ?? te funciono ??
  #6 (permalink)  
Antiguo 11/05/2006, 09:38
Avatar de freudII  
Fecha de Ingreso: abril-2006
Ubicación: Colombia
Mensajes: 14
Antigüedad: 18 años
Puntos: 0
Pregunta la carpeta excel donde se crea?
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:24.