• php导出execl


    <?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;
    }
  • 相关阅读:
    pycharm路径
    git常用命令
    分页
    router
    视图集
    Leanring TypeScript 中文版
    RXJS 系列 04
    RXJS 系列 03
    RXJS 系列 02
    RXJS 系列 01
  • 原文地址:https://www.cnblogs.com/mssql8/p/4477516.html
Copyright © 2020-2023  润新知