Okay, so this isn't really a Microsoft Excel file. I cheat and create a tab delimited file that, given the XLS file extension, Excel will happily open as if it were.
<?php // Trigger a download from the browser header("Content-Disposition: attachment; filename=\"foo.xls\""); header("Content-Type: application/vnd.ms-excel"); // Echo the data, tab delimited echo "Item 1\tItem 2\tItem3\n"; echo "9\t8\t7\n"; ?>
As you can see, it's as simple as spitting out the appropriate header and then a bit of tab (/t) delimited data, one set of columns per line (/n).