程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> PHP導出excel的超簡單方法

PHP導出excel的超簡單方法

編輯:PHP綜合
在PHP的開發過程中,經常會使用到一些數據的導出,一般都會導出excel,吾愛編程今天為大家分享一下PHP導出excel的一個超級簡單的方法,閒話就不多說了,直接上代碼:
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循環的時候先輸出一個英文逗號

*
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved