header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment; filename=UserInfo.xls"); require_once('./class.db.php'); $db = new DB('localhost', 'user', 'root', '123456'); $sql = 'select * from `user` order by `id` desc'; $ret = $db->get_results($sql); // 輸出內容如下: echo "ID"."\t"; echo "NickName"."\t"; echo "Sex"."\t"; echo "OpenId"."\t"; echo "regdate"."\t"; echo "\n"; $len = count($ret); for ( $i = 0; $i < $len; $i++ ) { echo $ret[$i]["id"]."\t"; echo $ret[$i]["nickname"]."\t"; echo $ret[$i]["gender"]."\t"; echo $ret[$i]["openid"]."\t"; echo $ret[$i]["regdate"]."\t"; echo "\n"; }
如果輸出的內容有數字,建議在for循環的時候先輸出一個英文逗號
*