网站地图    收藏   

主页 > 后端 > php资料库 >

thinkphp如何导出Excel_自学php网

来源:自学PHP网    时间:2014-12-04 22:12 作者: 阅读:

[导读] /*导出xls用户个人信息*/ function export(){ header(Content-type:application/octet-stream); header(Accept-Ranges:bytes); header(Content-type:application/vnd.ms-excel); header(Content-Disposition:attachment;filename=用户信息表.date...

/*导出xls用户个人信息*/
function export(){
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=用户信息表".date("Y-m-d").".xls");
header("Pragma: no-cache");
header("Expires: 0");
//导出xls 开始
$tag0 = iconv("UTF-8", "GB2312",'用户ID');
$tag1 = iconv("UTF-8", "GB2312",'用户名');
$tag2 = iconv("UTF-8", "GB2312",'待领取');
$tag3 = iconv("UTF-8", "GB2312",'奖金总数');
$tag4 = iconv("UTF-8", "GB2312",'开户行');
$tag5 = iconv("UTF-8", "GB2312",'开户城市');
$tag6 = iconv("UTF-8", "GB2312",'开户行地址');
$tag7 = iconv("UTF-8", "GB2312",'银行卡号');
$tag8 = iconv("UTF-8", "GB2312",'持卡人姓名');
echo "$tag0\t$tag1\t$tag2\t$tag3\t$tag4\t$tag5\t$tag6\t$tag7\n";
////查询的一张表
//$arr=M ('textpage')->field('username,count(id) as allcount,sum(price) as allprice ')->group('username')->select();
$field="crowd_textpage.tid,crowd_textpage.username,users.bankName,users.city,users.bankAddress,
users.bankCard,users.bankUsr,count(crowd_textpage.id) as allcount,sum(crowd_textpage.price) as allprice";
$arr = M ('textpage')->field($field)
->join('crowd_user as users ON crowd_textpage.username=users.username')
->group('crowd_textpage.username')
->select();
//dump(M ('textpage')->getLastSql());die;
foreach($arr as $key=>$val){
//$date = date('Y-m-d',$val['pay_time']);
$tid = iconv("UTF-8", "GB2312", $val['tid']);
$tid=$tid?$tid:'-';
$username = iconv("UTF-8", "GB2312", $val['username']);
$username=$username?$username:'-';
$allcount = iconv("UTF-8", "GB2312", $val['allcount']);
$allcount=$allcount?$allcount:'-';
$allprice = iconv("UTF-8", "GB2312", $val['allprice']);
$allprice=$allprice?$allprice:'-';
$bankName = iconv("UTF-8", "GB2312", $val['bankName']);
$bankName=$bankName?$bankName:'-';
$city = iconv("UTF-8", "GB2312", $val['city']);
$city=$city?$city:'-';
$bankAddress = iconv("UTF-8", "GB2312", $val['bankAddress']);
$bankAddress=$bankAddress?$bankAddress:'-';
$bankCard = iconv("UTF-8", "GB2312", $val['bankCard']);
$bankCard=$bankCard?$bankCard:'-';
$bankUsr = iconv("UTF-8", "GB2312", $val['bankUsr']);
$bankUsr=$bankUsr?$bankUsr:'-';
echo "$tid\t$username\t$allcount\t$allprice\t$bankName\t$city
\t$bankAddress\t'$bankCard\t$bankUsr\n";
}
}

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论