13
2014-02

thinkphp如何导出Excel

/*导出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";
        }
}

本文摘自:运达's blog


除非注明,文章均为史亚永原创,欢迎转载!转载请注明本文地址,谢谢。

本文地址:http://www.shiyayong.cn/post/248.html

评论列表:

1  php教程  2014-2-17 9:12:34 回复该留言  IP:124.200.255.11
好深呢,学习一下了。
  茶馆老板  2014-5-29 21:28:15 回复该留言  IP:106.120.181.131
这个也是在学习YII框架的时候遇到的呢,就自己试试
茶馆老板
php教程

发表评论:

(设置个性头像)

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

无觅相关文章插件,快速提升流量