Tema: PHP -> Excel
Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/05/2007, 20:21
Avatar de nicolaspar
nicolaspar
 
Fecha de Ingreso: noviembre-2004
Ubicación: Villa Ballester Bs-As|Ar
Mensajes: 2.002
Antigüedad: 20 años, 3 meses
Puntos: 34
Re: PHP -> Excel

Para pequeñas tablas estoy usando el siguiente, en su versión 1.0:
Código PHP:
require_once('__conn.php');
$r mysql_query('SELECT * FROM usuarios WHERE activo > -1 ORDER BY codigo DESC') or trigger_errormysql_error($conn), E_USER_ERROR );
$return '';
if( 
mysql_num_rows($r)>0){
    
$return .= '<table border=1>';
    
$cols 0;
    while(
$rs mysql_fetch_row($r)){
        
$return .= '<tr>';
        if(
$cols==0){
            
$cols count($rs);
            
$cols_names = array();
            for(
$i=0$i<$cols$i++){
                
$col_name mysql_field_name($r,$i);
                
$return .= '<th>'.htmlspecialchars($col_name).'</th>';
                
$cols_names[$i] = $col_name;
            }
            
$return .= '</tr><tr>';
        }
        for(
$i=0$i<$cols$i++){
            if(
$cols_names[$i] == 'fechasys'){
                
$return .= '<td>'.htmlspecialchars(date('d/m/Y H:i:s',$rs[$i])).'</td>';
            }else if(
$cols_names[$i] == 'activo'){
                
$return .= '<td>'.htmlspecialchars$rs[$i]==1'SI':'NO' ).'</td>';
            }else{
                
$return .= '<td>'.htmlspecialchars($rs[$i]).'</td>';
            }
        }
        
$return .= '</tr>';
    }
    
$return .= '</table>';
    
mysql_free_result($r);
}
header("Content-type: application/vnd-ms-excel; charset=iso-8859-1");
header("Content-Disposition: attachment; filename=Usuarios_".date('d-m-Y').".xls");
echo 
$return
Totalmente adaptable con solo cambiar el query.
__________________
Mi punto de partida es Que Bueno Lo Nuevo