学习笔记

  > php 导出EXCEL

php 导出EXCEL

php 导出excel 主要看下面代码

public function excel()
{
    $filename = date('Ymdhis');
    header("Pragma: public");  
    header("Expires: 0");  
    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");  

    
   	$lists = $this->db
			->order_by('case.id DESC')
			->where('case.isshow',1)
			->get('case')->result_array();

	foreach ($lists as $k => $v) 
	{
		$lists[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
		$lists[$k]['mobile'] = $this->Member_model->get_field($v['member_id'],'mobile');
		$lists[$k]['doctor_mobile'] = $v['mobile'];
		$lists[$k]['photos'] = $this->db->where('case_id',$v['id'])->count_all_results("photo");
		$res_photos = $this->db->select('id,des')->where('case_id',$v['id'])->get('photo')->result_array();
		$arr_photo_des = array();
		foreach ($res_photos as $_k => $_v) 
		{
			$arr_photo_des[] = "第".($_k+1)."小结描述:".$_v['des'];
		}
		$str = implode(' ', $arr_photo_des);
		$lists[$k]['photo_des'] = nl2br($str);
		$lists[$k]['status'] = $v['status'] == 1 ? "已审核" : "未审核";
		$lists[$k]['member_delete'] = $v['member_delete'] == 0 ? "正常" : "用户已删除";
		$lists[$k]['is_pay'] = $v['is_pay'] == 1 ? "已支付" : "未支付";
		
	}


    $table = '';
    $table .= "
    <table>
        <thead>
            <tr>
                <th class='name'>ID</th>
                <th class='name'>编号信息</th>
                <th class='name'>手机号</th>
                <th class='name'>状态</th>
                <th class='name'>删除状态</th>
                <th class='name'>快递单号</th>
                <th class='name'>小结数量</th>
                <th class='name'>小结描述</th>
                <th class='name'>医生姓名</th>
                <th class='name'>医生手机</th>
                <th class='name'>医院名称</th>
                <th class='name'>部门</th>
                <th class='name'>身份证号</th>
                <th class='name'>银行名称</th>
                <th class='name'>银联号</th>
                <th class='name'>银行账号</th>
                <th class='name'>是否支付</th>
                <th class='name'>创建时间</th>
            </tr>
        </thead>
        <tbody>";
    

    foreach ($lists as $k => $v) {

        $table .= 
            "<tr>
                <td class='name'>{$v['id']}</td>
                <td class='name'>{$v['sn']}</td>
                <td class='name'>{$v['mobile']}</td>
                <td class='name'>{$v['status']}</td>
                <td class='name'>{$v['member_delete']}</td>
                <td class='name'>{$v['sn2']}</td>
                <td class='name'>{$v['photos']}</td>
                <td class='name'>{$v['photo_des']}</td>
                <td class='name'>{$v['doctor_name']}</td>
                <td class='name'>{$v['doctor_mobile']}医生手机</td>
                <td class='name'>{$v['hospital']}医院名称</td>
                <td class='name'>{$v['department']}</td>
                <td class='name'>{$v['doctor_card_sn']}</td>
                <td class='name'>{$v['bank_name']}</td>
                <td class='name'>{$v['bank_sn']}</td>
                <td class='name'>{$v['bank_card_sn']}</td>
                <td class='name'>{$v['is_pay']}</td>
                <td class='name'>{$v['createtime']}</td>

            </tr>";
    }

    $table .= "</tbody>";

    echo $table;
    exit;
}  

主要使用了ci框架,不会的请看我的视频,或者加我qq微信,都可以。

lists为二位数组,从数据库取出的。

发布时间:2019-11-24,16:58:46

从数据库导出excel,php开发CI框架。

作者:澎蠡

让学习成为一种习惯,让知识交流变成一种生活方式。