码迷,mamicode.com
首页 > Web开发 > 详细

php导出execl

时间:2015-05-04 21:59:53      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

<?php
function export_excel($items,$fields,$fields_array,$name)
{  
      /*
      * 调用方法示例
      * $items = $this->mysql->getarr("select * from {$this->pre}user $where order by uid desc");
      * $fields=array(‘username‘,‘money‘,‘regtime‘);
      * $fields_array = array(‘username‘=>‘用户名‘,‘money‘=>‘电子币‘,‘regtime‘=>‘注册时间‘);
      * export_excel($items,$fields,$fields_array,date(‘Y-m-d‘).‘会员资料‘);
      */
      header("Content-type:application/vnd.ms-excel");
      header("Content-Disposition:filename=".$name.".xls");
      $str = "<table border=1><tr>";
      foreach ($fields as $value) {
        $str .= "<th>".iconv("UTF-8","GB2312",$fields_array[$value])."</th>";
      }
      $str .= "</tr>";
      foreach ($items as $item) {
        $str .= "<tr>";
        foreach ($fields as $value) { 
            // $val=
            if(strstr($value,time)){
                if(is_int($item[$value]+0)){ 
                    $item[$value]=date(Y-m-d H:i:s,$item[$value]);
                } 
            }
            $str .= "<td>".iconv("UTF-8","GB2312",$item[$value])."</td>";
        }
        $str .= "</tr>";
      }
      $str .= "</table>";
      $str .="<script>window.close();</script>";
      echo $str;
}

 

php导出execl

标签:

原文地址:http://www.cnblogs.com/mssql8/p/4477516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!