php輸出excel的簡單方法(csv格式)
阿新 • • 發佈:2019-02-12
1.
<?php header(“Content-type:application/vnd.ms-excel”); header(‘Content-Disposition: attachment;filename=”yingcai.xls”‘); ?> <table border=”1″> <tr> <td>使用者名稱</td> <td>密碼</td> </tr> <tr> <td>admin</td> <td>yingcai</td> </tr> </table>
2.
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment; filename=使用者資訊表.xls");
require_once('./class.db.php');
$db = new DB('localhost', 'app_vmovies', 'root', '123456');
$sql = 'select * from `user` order by `id` desc';
$ret = $db->get_results($sql);
// 輸出內容如下:
echo "ID"."t";
echo "暱稱"."t";
echo "性別"."t";
echo "OpenId"."t";
echo "平臺"."t";
echo "註冊日期"."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]["pf"]."t";
echo $ret[$i]["regdate"]."t";
echo "n";
}
3.另word格式匯入類似,,指定header就可以了:
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=doc.doc");