Salve a tutti, ho la necessità di esportare dei dati da mysql in formato ms-excel; in rete ho trovato e adattato questo script:

<?
$filename="sheet.xls";
header ("Content-Type: application/vnd.ms-excel");
header ("Content-Disposition: inline; filename=$filename");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang=it><head>
<title>Titolo</title></head>
<body>

<?php
$hostname = "localhost";
$database = "nomedb";
$username = "root";
$password= "pass";
$conn= mysql_pconnect($hostname, $username, $password) or die(mysql_error());
mysql_select_db($database, $conn);
$query = "SELECT id_treno, luogo, note FROM treni";
$clienti = mysql_query($query, $conn) or die(mysql_error());
$row_clienti = mysql_fetch_assoc($clienti);
?>

<?php
do {
$righe.= "\"".$row_clienti['id_treno']."\"\t\"".$row_clienti['luogo']."\"\t\"".$row_clienti['note']."\"\n";
} while ($row_clienti= mysql_fetch_assoc($clienti));
?>

<?php
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: nomefile.xls");
?>

<?php
print $righe;
exit;
?>
</body></html>

Viene in effetti generato il file xls, ma invece dei dati della query, sulla tabella vengono riportati i seguenti warning:

Warning: Cannot modify header information - headers already sent by (output started at C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\provaxls.php:11) in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\provaxls.php on line 30

Warning: Cannot modify header information - headers already sent by (output started at C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\provaxls.php:11) in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\provaxls.php on line 31

Qualcuno sà indicarmi dove sbaglio?
Grazie a tutti