I have to do this all the time with records from a MySQL database. Remember...to move accross columns you have to \t (tab)...then \n or \r to drop to the next row. Here is a short example:
<?php
header("Content-Type: application/octet-stream\n");
header("Content-Disposition: filename=\"my_excel_sheet.xls\"");
header("Content-transfer-encoding: binary\n");
print("Employee List\r");
print("Employee SSN\t Employee Name\r");
$sql = "select * from employees order by employee_ssn";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$ssn = $row["ssn"];
$name = $row["name"];
print("$ssn\t $name\r");
}
?>
...this works great for me. When the page loads it will popup with the save as dialog box. If it opens in the browser it will open as an excel sheet...you can turn that off in IE so it defaults to the "save as" box.
Hope that helps.