php 导出大量数据

public function daochu()
    {
        
           //防止跨域,打开缓冲区
        header('Access-Control-Allow-Origin:*');
        @ini_set("memory_limit", "1024M");
        @ini_set("max_execution_time", "40");
        ob_end_clean();
        ob_start();

        $filter = input();
        //查出订单表的数据  page(分页的开始位置, 每一页的条数)
        $articlesQuery = $this->model->alias('a');
        $articlesQuery->join('city u', 'a.province_id = u.id');
        $articlesQuery->join('city i', 'a.city_id = i.id');
        $field = 'a.*,u.name as p_name,i.name as c_name';
      
        $dataResult = $articlesQuery
            ->field($field)
            ->where('a.create_time', '>=', 0)
            ->where('a.delete_time', 0)
            ->select()
            ->toArray();


        //拼接数据
        $title = $filter['start_time'] . '——' . $filter['end_time'] . "导出列表";
        $headtitle = "<tr style='height:50px;'><th  style='height:60px;width:300px;font-size:22px;' colspan='14' >线索列表 导出时间:" . date("Y-m-d H:i:s", time()) . "</th></tr>";
        $titlename = "<tr>
            <th style='width:100px;'>ID</th>
            <th style='width:100px;'>省份</th>
            <th style='width:100px;'>城市</th>
            <th style='width:200px;'>公司名</th>
            <th style='width:100px;'>姓名</th>
            <th style='width:250px;'>提交时间</th>
         </tr>";
        $filename = $title . ".xls";
        $str = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\nxmlns=\"http://www.w3.org/TR/REC-html40\">\r\n<head>\r\n<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>";
        //组装表
        $str .= "<table border=1 style='text-align:center'>" . $title;
        $str .= $titlename;
        //获取缓存
        $itemData = cache('formSettingOption') ?? [];

        //组装表的td 数据
        foreach ($dataResult as $key => $vv) {
            $str .= "<tr style='text-align:center'>";
            $str .= "<td>" . ($vv['id'] ?? '暂无数据') . "</td>";
            $str .= "<td>" . ($vv['p_name'] ?? '暂无数据') . "</td>";
            $str .= "<td>" . ($vv['c_name'] ?? '暂无数据') . "</td>";
            $str .= "<td>" . ($vv['company'] ?? '暂无数据') . "</td>";
            $str .= "<td>" . ($vv['name'] ?? '暂无数据') . "</td>";
            $str .= "<td>" . date('Y-m-d H:i:s', $vv['create_time'] ?? '暂无数据') . "</td>";
            $str .= "</tr>\n";
        }
        $str .= "</table></body></html>";

        //下载
        header("Content-Type: application/vnd.ms-excel; name='excel'");
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment; filename=" . $filename);
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: no-cache");
        header("Expires: 0");

        exit($str);
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值