Principle: Direct output XLS file can be example;
ID Name Date1 Rongge 2004-09-202 Admin 2004-09-21
When saved into a.xls, it is an Excel file. Note: When saved, you have a space segmentation in every field, and each line data should be wrap code: PHP // Reprint, please indicate the phpteam $ title = "database Name: Test, Data Sheet: Test, Backup Date: ". Date (" YMD H: i: S "); $ SEP =" / T "; $ CRLF =" / n "; $ conn = @Mysql_Connect (" Localhost "," Root "," ") or Die (" cannot connect to the database "); @MYSQL_SELECT_DB (" Test ", $ conn); Header (" Content-Type: Application / VND.MS-Excel "); Header (" Content-disposition: attachment; filename = test.xls "); Header (" pragma: no-cache "); Header (" Expires: 0 "); Echo $ TITLE. $ CRLF. $ CRLF; $ query =" SELECT * "$ results"; $ query) or Die (mysql_error ()); $ fields = mysql_num_fields ($ RESULT); for ($ I = 0; $ FIELDS; $ i ) {echo mysql_field_name ($ { ) {echo mysql_field_name Result, $ I). $ SEP;} Echo $ CRLF; While ($ ROW = MySQL_FETCH_ROW ($ Result) {$ Line = ""; for ($ I = 0; $ i <$ FIELDS; $ I ) {$ Line. = $ row [$ I]. $ sep;} echo $ line. $ CRLF;}?>