desde hace un tiempo saque de estos mismos foros un code q hacia muy facil eso... solo debes cambiar las variables y la consulta obvio :)
Código:
<?php
header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=segmento34_reservados.xls");
$servidor="localhost";
$user="root";
$pass="";
$db="ips";
mysql_connect($servidor,$user,$pass);
mysql_select_db($db);
$qry=mysql_query("select * from red_192 WHERE INSTR(IP,\"192.168.34.\")and ping ='reservado'");
$campos = mysql_num_fields($qry);
$i=0;
echo "Planilla de Direcciones IP Reservadas Segmento 34";
echo " <center><table border=\"1\" align=\"center\">";
echo "<tr bgcolor=\"#000066\">
<td><font color=\"#ffffff\"><strong>IP</strong></font></td>
<td><font color=\"#ffffff\"><strong>Ping</strong></font></td>
<TD><font color=\"#ffffff\"><strong>Usuario</strong></font></TD>
<td><font color=\"#ffffff\"><strong>NombrePC</strong></font></td>
<TD><font color=\"#ffffff\"><strong>Mac</strong></font></TD>
<td><font color=\"#ffffff\"><strong>Dominio</strong></font></td>
<td><font color=\"#ffffff\"><strong>Departamento</strong></font></td>
<TD><font color=\"#ffffff\"><strong>Puertos</strong></font></TD>
<td><font color=\"#ffffff\"><strong>Comentarios</strong></font></td>
<TD><font color=\"#ffffff\"><strong>Empleado</strong></font></TD>
<td><font color=\"#ffffff\"><strong>SSOO</strong></font></td>
</tr><tr >";
while($row=mysql_fetch_array($qry))
{
echo "<tr>";
for($j=0; $j<$campos; $j++) {
echo "<td>".$row[$j]."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
Ojala te sirva
Suerte!