thinkphp5导出excel(原生)

public function  exportExcel($columName, $data){
        $table = '<table border=1>';
        if(!empty($columName) && is_array($columName)){
            $table .= "<thead><tr>";
            foreach($columName as $key=>$value){
            $table .= "<th style='background:#badffb'>{$value}</th>";
            }
            $table .= "</tr></thead>";
        }
        $table .= "<tbody>";
        if(!empty($data) && is_array($columName)){
            foreach($data as $k=>$v){
                $table .= "<tr>";
                foreach($v as $vk=>$vv){
            $table .= "<td>{$vv}</td>";
            }        
    
        $table .= "</tr>";
            }
        }
        $table .= "</tbody></table>";
        
        //通过header头控制输出excel表格
        header("Pragma: public");
        header("Expires: 0");

        //文件名
        $t=time();
        
        $fileName='反馈问题统计_'.date('Ymd_His', $t);

        
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");
        header('Content-Disposition:attachment;filename="'.$fileName.'.xls"');
        header("Content-Transfer-Encoding:binary");
        echo $table;
    }

    public function connectOrder()
    {
    $data=Db::table('表名')->field('需要的字段')->select();
        $header = array('序号');//表头
        
        //调用导出方法
        self::exportExcel($header, $data);
    }
本文来自投稿,不代表本站立场,如若转载,请注明出处:https://blog.itliujia.cn/info/20220395.html
-- 展开阅读全文 --
div水平垂直居中
« 上一篇 02-10
uni-app 中定义全局变量globalData注意事项
下一篇 » 04-07

发表评论