Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/09/2008, 07:57
susan_
 
Fecha de Ingreso: agosto-2008
Mensajes: 173
Antigüedad: 16 años, 7 meses
Puntos: 0
exportar tabla a excel

hola alguien esta familiarizado con la exportacion de tablas a excel?..
yo encontre un codigo .. y lo probe pero me marca error...

Código PHP:
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=archivo.xls");
$servidor="localhost";
$user="root";
$pass="";
$db="ctrlpresupuestos"
mysql_connect($servidor,$user,$pass); 
mysql_select_db($db); $qry=mysql_query("select * from "."comparativa"); 
$campos mysql_num_fields($qry); 
$i=0
ob_start(); 

echo 
"<table border='1'><tr>";

while(
$i<$campos){ 
echo 
"<td bgcolor='00ff00'><b>".mysql_field_name ($qry$i);
echo 
"</b></td>";
$i++;}

echo 
"</tr>";

while(
$row=mysql_fetch_array($qry)){ 
echo 
"<tr>";

for(
$j=0$j<$campos$j++) { 

echo 
"<td>".$row[$j]."</td>"; }

echo 
"</tr>"; }

echo 
"</table>";

$tabla ob_get_contents();

ob_end_clean(); 

$archivo="C:\wamp\www\WBS\archivo.xls";

$p=fopen("$archivo","a"); 

if(
$p){
fputs($p,$tabla); } 

fclose($p); 

echo 
"<a rel='nofollow' href=$archivo>Ver archivo</a>"
cuando lo abro de la carpeta de www.. del wamp ... me pregunta que si lo quiero abrir o guardar... ya le di en las dos opciones y da lo mismo..

al abrir el archivo me dice : el archivo que intenta abrir tiene otro formato que el especificado en el formato... bla bla..

le doy que si lo quiero abrir... y me sale el vinvulo de VER ARCHIVO... le doy clic y me aparece lo siguiente:

Código:
Warning: fopen(WBS/archivo.xls) [function.fopen]: failed to open stream: No such file or directory in C:\wamp\www\WBS\exportar.php on line 48

Warning: fclose(): supplied argument is not a valid stream resource in C:\wamp\www\WBS\exportar.php on line 53
no se si puedan ayudarme...