send("filename.xls"); // Add a worksheet to the file, returning an object to add data to $sheet =& $xls->addWorksheet('Worksheet Name'); $tabledata = get_table_data("table"); $i=0; foreach($tabledata as $table) { $sheet->write(0, $i, $table['name']); $i++; } $result = sqlquery("SELECT * from table"); $data = get_result($result); $i=1; foreach($data as $d) { $j=0; foreach($tabledata as $table) { $sheet->write($i, $j, $d[$table['name']]); $j++; } $i++; } // Finish the spreadsheet, dumping it to the browser $xls->close(); ?>