loading....

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
<?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;
}

 

posted on 2015-05-04 21:06  程序加载中  阅读(268)  评论(0编辑  收藏  举报