En un pequeño Sistema de Fichas para COFOPRI (Chiclayo), ya tenía el reporte en Formato PDF pero se requería en formato XLS de Excel asi que empecé la busqueda de información primero con el tío Google. Y en unos segundos ya estaba viendo como hacer esto; por lo visto no era el primero que necesitaba a pedido del jefe usar este formato propietario. Pero entre tantas soluciones busque la mejor y encontré una que me parecía sencilla y fácil asi que utilicé esa, se trata sólo de pasarle cabeceras al archivo:

header(”Content-type: application/vnd.ms-excel”);
header(”Content-Disposition: attachment; filename=excel.xls”); 

Y los datos formateados en una Tabla HTML y listo.
Ahí les dejo un ejemplo sencillo de cómo debería ser, saludos.

<?php
header(”Content-type: application/vnd.ms-excel”);
header(”Content-Disposition: attachment; filename=excel.xls”);

// … pasos de conexióna la BD y demás 

//Logo
$logo = “http://www.tuwebaqui.com/imagenes/logocofopri.gif“;
$date = date(”d/m/Y”);
$time = date(”H:m:s”);

//Tu sentencia SQL
$sql = “SELECT  …”

$rs = mysql_query($sql,$link) or die(mysql_error($link) . “<br>$sql”);
$campos = mysql_num_fields($rs);
$filas  = mysql_num_rows($rs);
$temp=”";
?>
<table border=”0″>
  <tr>
  <th align=”left”><img src=”<?=$logo?>”></th>
  </tr>
  <tr>
  <th> </th> 
  <th> </th> 
  <th> </th>   
  <th align=”right” bgcolor=”#CCCCCC”>Fecha: </th>       
  <th align=”left”><?=$date?></th>  
  </tr>
  <tr></tr>
</table>    
<table border=”1″>
  <tr>
  <th bgcolor=”#CCCCCC”><?=”ETAPA_SECTOR”?></th>
  <th bgcolor=”#CCCCCC”><?=”COD_PREDIO”?></th>
  <th bgcolor=”#CCCCCC”><?=”MANZANA”?></th>
  <th bgcolor=”#CCCCCC”><?=”LOTE”?></th>
  <th bgcolor=”#CCCCCC”><?=”DERIVADO A”?></th>
  </tr>
<?
while($datos = mysql_fetch_row($rs)){  ?>
 <tr>
 <td align=”left”><?=$datos[10]?></td>
 <td align=”left”><?=$datos[0]?></td>
 <td align=”left”><?=$datos[1]?></td>
 <td align=”left”><?=$datos[2]?></td>
 <td align=”left”><?=$datos[9]?></td>
 </tr> 
<? 
}
?>
 <tr>
 <th align=”left” bgcolor=”#CCCCCC”><?=”Total Fichas”?></th>
 <th align=”left”><?=$filas?></th>
 <th> </th>
 <th align=”right” bgcolor=”#CCCCCC”>Hora:</th> 
 <th align=”left”><?=$time?></th>
 </tr>
</table>

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!