Estimado
Lo que estas haciendo es imprimir una tabla html y el excel es capaz de interpretar el html como una planilla, pero suceded los problemas que comentas.
Te recomiendo utilizar PEAR:Spreadsheet para generar un fichero Excel real, te adjunto un ejemplo (necesitas pear y spresheet)
Código PHP:
<?php
// Example by deerme.org
$pear = "/usr/share/php5/php/";
ini_set("include_path",ini_get("include_path").":$pear");
require_once("Spreadsheet/Excel/Writer.php");
function data_to_excel( $array , $name = "Hoja" )
{
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$name.xls");
$x = & new Spreadsheet_Excel_Writer();
$x->setVersion(8);
$s = &$x->addWorksheet( $name );
$sx = 0;
$sy = 0;
foreach( $array as $k => $r )
{
foreach( $r as $kk => $c )
{
if ( is_int( $c ) or is_float( $c ) )
$s->write($sx, $sy, $c);
else
$s->writeString($sx, $sy, $c);
$sy++;
}
$sx++;
$sy = 0;
}
$x->close();
}
$data[] = array( "Id" , "Codigo" , "Producto" , "Valor" , "Stock" , "Costo" , "YYYY" );
for( $i=0;$i<100;$i++ )
{
$data[] = array( ($i + 1 ) , "00000000".$i , "PK1000".$i , rand(10000,99999) , rand(1,100) , rand(1000,9999)*0.79 , "1-2" );
}
data_to_excel($data);
?>