Hola gracias por costentar, pero ya le encontre la solución, de la siguiente manera:
Código PHP:
define(db_host, "localhost");
define(db_user, "root");
define(db_pass, "");
define(db_link, mysql_connect(db_host,db_user,db_pass));
define(db_name, "productiva_contactos");
mysql_select_db(db_name);
/********************************************
Write the query, call it, and find the number of fields
/********************************************/
$qry =mysql_query("SELECT * from contacto");
$campos = mysql_num_fields($qry);
$i=0;
/********************************************
Extract field names and write them to the $header
variable
/********************************************/
echo " <center><table border=\"1\" align=\"center\">";
echo "<tr bgcolor=\"#336666\">
<td><font color=\"#ffffff\"><strong>Nombre Empresa</strong></font></td>
<td><font color=\"#ffffff\"><strong>Dirección</strong></font></td>
<TD><font color=\"#ffffff\"><strong>Ciudad</strong></font></TD>
<td><font color=\"#ffffff\"><strong>Nombre contacto</strong></font></td>
<td><font color=\"#ffffff\"><strong>Departamento</strong></font></td>
</tr>";
while($row=mysql_fetch_array($qry))
{
echo "<tr>";
for($j=0; $j<$campos; $j++) {
echo "<td>".$row[$j]."</td>";
}
echo "</tr>";
}
echo "</table>";
/********************************************
Set the automatic downloadn section
/********************************************/
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=consulta.xls");
header("Pragma: no-cache");
header("Expires: 0");
ing_aprendiz