Here's one I use: <?php header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=XL_".date("m-d-Y").".xls"); header("Pragma: no-cache"); header("Expires: 0"); $hostname = "localhost"; $username = "YOUR USERNAME"; $password = "YOUR PASSWORD"; $database = "YOUR DATABASE NAME"; $usertable = "YOUR TABLE"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die("Unable to select database"); $select = "SELECT * FROM $usertable"; $export = mysql_query($select); $count = mysql_num_fields($export); for ($i = 0; $i < $count; $i++) { $header .= mysql_field_name($export, $i)."\t"; } while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r", "", $data); if ($data == "") { $data = "\n(0) Records Found!\n"; } print "$header\n$data"; ?> PHP: