Home > Backend Development > PHP Tutorial > 超简单PHP导出excel方法

超简单PHP导出excel方法

WBOY
Release: 2016-06-20 13:03:04
Original
1372 people have browsed it

PHP导出excel方法

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";
}
Copy after login

 

如果输出的内容有数字,建议在for循环的时候先输出一个英文逗号


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template