使用php在xls中保存Mysql数据

I want to export data in xls format using PHP. But instead of download information, they are displayed in my web page.

//connection to database
//building of all information -> ($righe)

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: esporta_utenti.xls");
print $righe;
exit();  

$righe is my tuple

header('Pragma: public');   // required
header('Expires: 0');       // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file_name)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: '.$mime); // file mime type
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file_name));    // provide file size
header('Connection: close');
readfile($file_name);       // push it out
exit();

This code was originally Published here http://davidwalsh.name/php-force-download . And can be referred for a detailed explanation of the Code.